88//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010use 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 } ;
1412use crate :: stable_mir:: { self , Context } ;
1513use rustc_hir as hir;
1614use rustc_middle:: mir;
@@ -103,7 +101,7 @@ impl<'tcx> Tables<'tcx> {
103101 } ,
104102 ty:: Adt ( adt_def, generic_args) => TyKind :: RigidTy ( RigidTy :: Adt (
105103 rustc_internal:: adt_def ( adt_def. did ( ) ) ,
106- self . generic_args ( generic_args ) ,
104+ generic_args. stable ( self ) ,
107105 ) ) ,
108106 ty:: Foreign ( def_id) => {
109107 TyKind :: RigidTy ( RigidTy :: Foreign ( rustc_internal:: foreign_def ( * def_id) ) )
@@ -123,17 +121,17 @@ impl<'tcx> Tables<'tcx> {
123121 ) ) ,
124122 ty:: FnDef ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: FnDef (
125123 rustc_internal:: fn_def ( * def_id) ,
126- self . generic_args ( generic_args ) ,
124+ generic_args. stable ( self ) ,
127125 ) ) ,
128126 ty:: FnPtr ( _) => todo ! ( ) ,
129127 ty:: Dynamic ( _, _, _) => todo ! ( ) ,
130128 ty:: Closure ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: Closure (
131129 rustc_internal:: closure_def ( * def_id) ,
132- self . generic_args ( generic_args ) ,
130+ generic_args. stable ( self ) ,
133131 ) ) ,
134132 ty:: Generator ( def_id, generic_args, movability) => TyKind :: RigidTy ( RigidTy :: Generator (
135133 rustc_internal:: generator_def ( * def_id) ,
136- self . generic_args ( generic_args ) ,
134+ generic_args. stable ( self ) ,
137135 match movability {
138136 hir:: Movability :: Static => Movability :: Static ,
139137 hir:: Movability :: Movable => Movability :: Movable ,
@@ -164,24 +162,6 @@ impl<'tcx> Tables<'tcx> {
164162 self . types . push ( ty) ;
165163 stable_mir:: ty:: Ty ( id)
166164 }
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- }
185165}
186166
187167/// Build a stable mir crate from a given crate number.
@@ -582,3 +562,22 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
582562 }
583563 }
584564}
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