This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ pub fn fn_def(did: DefId) -> stable_mir::ty::FnDef {
3939 with_tables ( |t| t. fn_def ( did) )
4040}
4141
42+ pub fn closure_def ( did : DefId ) -> stable_mir:: ty:: ClosureDef {
43+ with_tables ( |t| t. closure_def ( did) )
44+ }
45+
4246impl < ' tcx > Tables < ' tcx > {
4347 pub fn item_def_id ( & self , item : & stable_mir:: CrateItem ) -> DefId {
4448 self . def_ids [ item. 0 ]
@@ -60,6 +64,10 @@ impl<'tcx> Tables<'tcx> {
6064 stable_mir:: ty:: FnDef ( self . create_def_id ( did) )
6165 }
6266
67+ pub fn closure_def ( & mut self , did : DefId ) -> stable_mir:: ty:: ClosureDef {
68+ stable_mir:: ty:: ClosureDef ( self . create_def_id ( did) )
69+ }
70+
6371 fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
6472 // FIXME: this becomes inefficient when we have too many ids
6573 for ( i, & d) in self . def_ids . iter ( ) . enumerate ( ) {
Original file line number Diff line number Diff line change @@ -148,7 +148,25 @@ impl<'tcx> Tables<'tcx> {
148148 ) ) ,
149149 ty:: FnPtr ( _) => todo ! ( ) ,
150150 ty:: Dynamic ( _, _, _) => todo ! ( ) ,
151- ty:: Closure ( _, _) => todo ! ( ) ,
151+ ty:: Closure ( def_id, generic_args) => TyKind :: RigidTy ( RigidTy :: Closure (
152+ rustc_internal:: closure_def ( * def_id) ,
153+ GenericArgs (
154+ generic_args
155+ . iter ( )
156+ . map ( |arg| match arg. unpack ( ) {
157+ ty:: GenericArgKind :: Lifetime ( region) => {
158+ GenericArgKind :: Lifetime ( opaque ( & region) )
159+ }
160+ ty:: GenericArgKind :: Type ( ty) => {
161+ GenericArgKind :: Type ( self . intern_ty ( ty) )
162+ }
163+ ty:: GenericArgKind :: Const ( const_) => {
164+ GenericArgKind :: Const ( opaque ( & const_) )
165+ }
166+ } )
167+ . collect ( ) ,
168+ ) ,
169+ ) ) ,
152170 ty:: Generator ( _, _, _) => todo ! ( ) ,
153171 ty:: Never => TyKind :: RigidTy ( RigidTy :: Never ) ,
154172 ty:: Tuple ( fields) => TyKind :: RigidTy ( RigidTy :: Tuple (
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub enum RigidTy {
3333 RawPtr ( Ty , Mutability ) ,
3434 Ref ( Region , Ty , Mutability ) ,
3535 FnDef ( FnDef , GenericArgs ) ,
36+ Closure ( ClosureDef , GenericArgs ) ,
3637 Never ,
3738 Tuple ( Vec < Ty > ) ,
3839}
@@ -69,6 +70,9 @@ pub struct ForeignDef(pub(crate) DefId);
6970#[ derive( Clone , PartialEq , Eq , Debug ) ]
7071pub struct FnDef ( pub ( crate ) DefId ) ;
7172
73+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
74+ pub struct ClosureDef ( pub ( crate ) DefId ) ;
75+
7276#[ derive( Clone , PartialEq , Eq , Debug ) ]
7377pub struct AdtDef ( pub ( crate ) DefId ) ;
7478
You can’t perform that action at this time.
0 commit comments