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 {
39
39
with_tables ( |t| t. fn_def ( did) )
40
40
}
41
41
42
+ pub fn closure_def ( did : DefId ) -> stable_mir:: ty:: ClosureDef {
43
+ with_tables ( |t| t. closure_def ( did) )
44
+ }
45
+
42
46
impl < ' tcx > Tables < ' tcx > {
43
47
pub fn item_def_id ( & self , item : & stable_mir:: CrateItem ) -> DefId {
44
48
self . def_ids [ item. 0 ]
@@ -60,6 +64,10 @@ impl<'tcx> Tables<'tcx> {
60
64
stable_mir:: ty:: FnDef ( self . create_def_id ( did) )
61
65
}
62
66
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
+
63
71
fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
64
72
// FIXME: this becomes inefficient when we have too many ids
65
73
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> {
148
148
) ) ,
149
149
ty:: FnPtr ( _) => todo ! ( ) ,
150
150
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
+ ) ) ,
152
170
ty:: Generator ( _, _, _) => todo ! ( ) ,
153
171
ty:: Never => TyKind :: RigidTy ( RigidTy :: Never ) ,
154
172
ty:: Tuple ( fields) => TyKind :: RigidTy ( RigidTy :: Tuple (
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ pub enum RigidTy {
33
33
RawPtr ( Ty , Mutability ) ,
34
34
Ref ( Region , Ty , Mutability ) ,
35
35
FnDef ( FnDef , GenericArgs ) ,
36
+ Closure ( ClosureDef , GenericArgs ) ,
36
37
Never ,
37
38
Tuple ( Vec < Ty > ) ,
38
39
}
@@ -69,6 +70,9 @@ pub struct ForeignDef(pub(crate) DefId);
69
70
#[ derive( Clone , PartialEq , Eq , Debug ) ]
70
71
pub struct FnDef ( pub ( crate ) DefId ) ;
71
72
73
+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
74
+ pub struct ClosureDef ( pub ( crate ) DefId ) ;
75
+
72
76
#[ derive( Clone , PartialEq , Eq , Debug ) ]
73
77
pub struct AdtDef ( pub ( crate ) DefId ) ;
74
78
You can’t perform that action at this time.
0 commit comments