8
8
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
9
9
10
10
use crate :: rustc_internal:: { self , opaque} ;
11
- use crate :: stable_mir:: ty:: {
12
- FloatTy , GenericArgKind , GenericArgs , IntTy , Movability , RigidTy , TyKind , UintTy ,
13
- } ;
11
+ use crate :: stable_mir:: ty:: { FloatTy , IntTy , Movability , RigidTy , TyKind , UintTy } ;
14
12
use crate :: stable_mir:: { self , Context } ;
15
13
use rustc_hir as hir;
16
14
use rustc_middle:: mir;
@@ -103,7 +101,7 @@ impl<'tcx> Tables<'tcx> {
103
101
} ,
104
102
ty:: Adt ( adt_def, generic_args) => TyKind :: RigidTy ( RigidTy :: Adt (
105
103
rustc_internal:: adt_def ( adt_def. did ( ) ) ,
106
- self . generic_args ( generic_args ) ,
104
+ generic_args. stable ( self ) ,
107
105
) ) ,
108
106
ty:: Foreign ( def_id) => {
109
107
TyKind :: RigidTy ( RigidTy :: Foreign ( rustc_internal:: foreign_def ( * def_id) ) )
@@ -123,17 +121,17 @@ impl<'tcx> Tables<'tcx> {
123
121
) ) ,
124
122
ty:: FnDef ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: FnDef (
125
123
rustc_internal:: fn_def ( * def_id) ,
126
- self . generic_args ( generic_args ) ,
124
+ generic_args. stable ( self ) ,
127
125
) ) ,
128
126
ty:: FnPtr ( _) => todo ! ( ) ,
129
127
ty:: Dynamic ( _, _, _) => todo ! ( ) ,
130
128
ty:: Closure ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: Closure (
131
129
rustc_internal:: closure_def ( * def_id) ,
132
- self . generic_args ( generic_args ) ,
130
+ generic_args. stable ( self ) ,
133
131
) ) ,
134
132
ty:: Generator ( def_id, generic_args, movability) => TyKind :: RigidTy ( RigidTy :: Generator (
135
133
rustc_internal:: generator_def ( * def_id) ,
136
- self . generic_args ( generic_args ) ,
134
+ generic_args. stable ( self ) ,
137
135
match movability {
138
136
hir:: Movability :: Static => Movability :: Static ,
139
137
hir:: Movability :: Movable => Movability :: Movable ,
@@ -164,24 +162,6 @@ impl<'tcx> Tables<'tcx> {
164
162
self . types . push ( ty) ;
165
163
stable_mir:: ty:: Ty ( id)
166
164
}
167
-
168
- fn generic_args (
169
- & mut self ,
170
- generic_args : & ty:: GenericArgs < ' tcx > ,
171
- ) -> stable_mir:: ty:: GenericArgs {
172
- GenericArgs (
173
- generic_args
174
- . iter ( )
175
- . map ( |arg| match arg. unpack ( ) {
176
- ty:: GenericArgKind :: Lifetime ( region) => {
177
- GenericArgKind :: Lifetime ( opaque ( & region) )
178
- }
179
- ty:: GenericArgKind :: Type ( ty) => GenericArgKind :: Type ( self . intern_ty ( ty) ) ,
180
- ty:: GenericArgKind :: Const ( const_) => GenericArgKind :: Const ( opaque ( & const_) ) ,
181
- } )
182
- . collect ( ) ,
183
- )
184
- }
185
165
}
186
166
187
167
/// Build a stable mir crate from a given crate number.
@@ -582,3 +562,22 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
582
562
}
583
563
}
584
564
}
565
+
566
+ impl < ' tcx > Stable < ' tcx > for ty:: GenericArgs < ' tcx > {
567
+ type T = stable_mir:: ty:: GenericArgs ;
568
+ fn stable ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
569
+ use stable_mir:: ty:: { GenericArgKind , GenericArgs } ;
570
+
571
+ GenericArgs (
572
+ self . iter ( )
573
+ . map ( |arg| match arg. unpack ( ) {
574
+ ty:: GenericArgKind :: Lifetime ( region) => {
575
+ GenericArgKind :: Lifetime ( opaque ( & region) )
576
+ }
577
+ ty:: GenericArgKind :: Type ( ty) => GenericArgKind :: Type ( tables. intern_ty ( ty) ) ,
578
+ ty:: GenericArgKind :: Const ( const_) => GenericArgKind :: Const ( opaque ( & const_) ) ,
579
+ } )
580
+ . collect ( ) ,
581
+ )
582
+ }
583
+ }
0 commit comments