@@ -9,8 +9,8 @@ use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
99use rustc_span:: Symbol ;
1010use stable_mir:: mir:: mono:: { Instance , MonoItem , StaticDef } ;
1111use stable_mir:: ty:: {
12- Binder , BoundRegionKind , BoundTyKind , BoundVariableKind , ClosureKind , Const , GenericArgKind ,
13- GenericArgs , Region , TraitRef , Ty ,
12+ AdtDef , Binder , BoundRegionKind , BoundTyKind , BoundVariableKind , ClosureKind , Const , FloatTy ,
13+ GenericArgKind , GenericArgs , IntTy , Region , RigidTy , TraitRef , Ty , UintTy ,
1414} ;
1515use stable_mir:: { AllocId , CrateItem , DefId } ;
1616
@@ -63,6 +63,82 @@ impl<'tcx> RustcInternal<'tcx> for Ty {
6363 }
6464}
6565
66+ impl < ' tcx > RustcInternal < ' tcx > for RigidTy {
67+ type T = rustc_ty:: TyKind < ' tcx > ;
68+
69+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
70+ match self {
71+ RigidTy :: Bool => rustc_ty:: TyKind :: Bool ,
72+ RigidTy :: Char => rustc_ty:: TyKind :: Char ,
73+ RigidTy :: Int ( int_ty) => rustc_ty:: TyKind :: Int ( int_ty. internal ( tables) ) ,
74+ RigidTy :: Uint ( uint_ty) => rustc_ty:: TyKind :: Uint ( uint_ty. internal ( tables) ) ,
75+ RigidTy :: Float ( float_ty) => rustc_ty:: TyKind :: Float ( float_ty. internal ( tables) ) ,
76+ RigidTy :: Never => rustc_ty:: TyKind :: Never ,
77+ RigidTy :: Array ( ty, cnst) => {
78+ rustc_ty:: TyKind :: Array ( ty. internal ( tables) , ty_const ( cnst, tables) )
79+ }
80+ RigidTy :: Adt ( def, args) => {
81+ rustc_ty:: TyKind :: Adt ( def. internal ( tables) , args. internal ( tables) )
82+ }
83+ RigidTy :: Str => rustc_ty:: TyKind :: Str ,
84+ RigidTy :: Slice ( ty) => rustc_ty:: TyKind :: Slice ( ty. internal ( tables) ) ,
85+ RigidTy :: RawPtr ( ..)
86+ | RigidTy :: Ref ( ..)
87+ | RigidTy :: Foreign ( _)
88+ | RigidTy :: FnDef ( _, _)
89+ | RigidTy :: FnPtr ( _)
90+ | RigidTy :: Closure ( ..)
91+ | RigidTy :: Coroutine ( ..)
92+ | RigidTy :: CoroutineWitness ( ..)
93+ | RigidTy :: Dynamic ( ..)
94+ | RigidTy :: Tuple ( ..) => {
95+ todo ! ( )
96+ }
97+ }
98+ }
99+ }
100+
101+ impl < ' tcx > RustcInternal < ' tcx > for IntTy {
102+ type T = rustc_ty:: IntTy ;
103+
104+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
105+ match self {
106+ IntTy :: Isize => rustc_ty:: IntTy :: Isize ,
107+ IntTy :: I8 => rustc_ty:: IntTy :: I8 ,
108+ IntTy :: I16 => rustc_ty:: IntTy :: I16 ,
109+ IntTy :: I32 => rustc_ty:: IntTy :: I32 ,
110+ IntTy :: I64 => rustc_ty:: IntTy :: I64 ,
111+ IntTy :: I128 => rustc_ty:: IntTy :: I128 ,
112+ }
113+ }
114+ }
115+
116+ impl < ' tcx > RustcInternal < ' tcx > for UintTy {
117+ type T = rustc_ty:: UintTy ;
118+
119+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
120+ match self {
121+ UintTy :: Usize => rustc_ty:: UintTy :: Usize ,
122+ UintTy :: U8 => rustc_ty:: UintTy :: U8 ,
123+ UintTy :: U16 => rustc_ty:: UintTy :: U16 ,
124+ UintTy :: U32 => rustc_ty:: UintTy :: U32 ,
125+ UintTy :: U64 => rustc_ty:: UintTy :: U64 ,
126+ UintTy :: U128 => rustc_ty:: UintTy :: U128 ,
127+ }
128+ }
129+ }
130+
131+ impl < ' tcx > RustcInternal < ' tcx > for FloatTy {
132+ type T = rustc_ty:: FloatTy ;
133+
134+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
135+ match self {
136+ FloatTy :: F32 => rustc_ty:: FloatTy :: F32 ,
137+ FloatTy :: F64 => rustc_ty:: FloatTy :: F64 ,
138+ }
139+ }
140+ }
141+
66142fn ty_const < ' tcx > ( constant : & Const , tables : & mut Tables < ' tcx > ) -> rustc_ty:: Const < ' tcx > {
67143 match constant. internal ( tables) {
68144 rustc_middle:: mir:: Const :: Ty ( c) => c,
@@ -183,6 +259,17 @@ impl<'tcx> RustcInternal<'tcx> for ClosureKind {
183259 }
184260}
185261
262+ impl < ' tcx > RustcInternal < ' tcx > for AdtDef {
263+ type T = rustc_ty:: AdtDef < ' tcx > ;
264+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
265+ let ty = tables. tcx . type_of ( self . 0 . internal ( & mut * tables) ) . instantiate_identity ( ) . kind ( ) ;
266+ let rustc_ty:: TyKind :: Adt ( def, _) = ty else {
267+ panic ! ( "Expected an ADT definition, but found: {ty:?}" )
268+ } ;
269+ * def
270+ }
271+ }
272+
186273impl < ' tcx , T > RustcInternal < ' tcx > for & T
187274where
188275 T : RustcInternal < ' tcx > ,
0 commit comments