mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Extract generic_args function
This commit is contained in:
parent
ed32347689
commit
db35f1de2f
@ -8,7 +8,9 @@
|
||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||
|
||||
use crate::rustc_internal::{self, opaque};
|
||||
use crate::stable_mir::ty::{FloatTy, GenericArgKind, GenericArgs, IntTy, Movability, RigidTy, TyKind, UintTy};
|
||||
use crate::stable_mir::ty::{
|
||||
FloatTy, GenericArgKind, GenericArgs, IntTy, Movability, RigidTy, TyKind, UintTy,
|
||||
};
|
||||
use crate::stable_mir::{self, Context};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::mir;
|
||||
@ -97,22 +99,7 @@ impl<'tcx> Tables<'tcx> {
|
||||
},
|
||||
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
|
||||
rustc_internal::adt_def(adt_def.did()),
|
||||
GenericArgs(
|
||||
generic_args
|
||||
.iter()
|
||||
.map(|arg| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(region) => {
|
||||
GenericArgKind::Lifetime(opaque(®ion))
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
GenericArgKind::Type(self.intern_ty(ty))
|
||||
}
|
||||
ty::GenericArgKind::Const(const_) => {
|
||||
GenericArgKind::Const(opaque(&const_))
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
self.generic_args(generic_args),
|
||||
)),
|
||||
ty::Foreign(def_id) => {
|
||||
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
|
||||
@ -130,67 +117,21 @@ impl<'tcx> Tables<'tcx> {
|
||||
}
|
||||
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
|
||||
rustc_internal::fn_def(*def_id),
|
||||
GenericArgs(
|
||||
generic_args
|
||||
.iter()
|
||||
.map(|arg| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(region) => {
|
||||
GenericArgKind::Lifetime(opaque(®ion))
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
GenericArgKind::Type(self.intern_ty(ty))
|
||||
}
|
||||
ty::GenericArgKind::Const(const_) => {
|
||||
GenericArgKind::Const(opaque(&const_))
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
self.generic_args(generic_args),
|
||||
)),
|
||||
ty::FnPtr(_) => todo!(),
|
||||
ty::Dynamic(_, _, _) => todo!(),
|
||||
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
||||
rustc_internal::closure_def(*def_id),
|
||||
GenericArgs(
|
||||
generic_args
|
||||
.iter()
|
||||
.map(|arg| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(region) => {
|
||||
GenericArgKind::Lifetime(opaque(®ion))
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
GenericArgKind::Type(self.intern_ty(ty))
|
||||
}
|
||||
ty::GenericArgKind::Const(const_) => {
|
||||
GenericArgKind::Const(opaque(&const_))
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
self.generic_args(generic_args),
|
||||
)),
|
||||
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
|
||||
rustc_internal::generator_def(*def_id),
|
||||
GenericArgs(
|
||||
generic_args
|
||||
.iter()
|
||||
.map(|arg| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(region) => {
|
||||
GenericArgKind::Lifetime(opaque(®ion))
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => {
|
||||
GenericArgKind::Type(self.intern_ty(ty))
|
||||
}
|
||||
ty::GenericArgKind::Const(const_) => {
|
||||
GenericArgKind::Const(opaque(&const_))
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
self.generic_args(generic_args),
|
||||
match movability {
|
||||
hir::Movability::Static => Movability::Static,
|
||||
hir::Movability::Movable => Movability::Movable,
|
||||
|
||||
}
|
||||
},
|
||||
)),
|
||||
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
||||
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
||||
@ -217,6 +158,24 @@ impl<'tcx> Tables<'tcx> {
|
||||
self.types.push(ty);
|
||||
stable_mir::ty::Ty(id)
|
||||
}
|
||||
|
||||
fn generic_args(
|
||||
&mut self,
|
||||
generic_args: &ty::GenericArgs<'tcx>,
|
||||
) -> stable_mir::ty::GenericArgs {
|
||||
GenericArgs(
|
||||
generic_args
|
||||
.iter()
|
||||
.map(|arg| match arg.unpack() {
|
||||
ty::GenericArgKind::Lifetime(region) => {
|
||||
GenericArgKind::Lifetime(opaque(®ion))
|
||||
}
|
||||
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(self.intern_ty(ty)),
|
||||
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a stable mir crate from a given crate number.
|
||||
|
Loading…
Reference in New Issue
Block a user