6
6
// Prefer importing stable_mir over internal rustc constructs to make this file more readable.
7
7
use crate :: rustc_smir:: Tables ;
8
8
use rustc_middle:: ty:: { self as rustc_ty, Ty as InternalTy } ;
9
- use stable_mir:: ty:: { Const , GenericArgKind , GenericArgs , Region , Ty } ;
10
- use stable_mir:: DefId ;
9
+ use rustc_span:: Symbol ;
10
+ use stable_mir:: mir:: mono:: { Instance , MonoItem , StaticDef } ;
11
+ use stable_mir:: ty:: {
12
+ Binder , BoundRegionKind , BoundTyKind , BoundVariableKind , ClosureKind , Const , GenericArgKind ,
13
+ GenericArgs , Region , TraitRef , Ty ,
14
+ } ;
15
+ use stable_mir:: { AllocId , CrateItem , DefId } ;
11
16
12
17
use super :: RustcInternal ;
13
18
19
+ impl < ' tcx > RustcInternal < ' tcx > for CrateItem {
20
+ type T = rustc_span:: def_id:: DefId ;
21
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
22
+ self . 0 . internal ( tables)
23
+ }
24
+ }
25
+
14
26
impl < ' tcx > RustcInternal < ' tcx > for DefId {
15
27
type T = rustc_span:: def_id:: DefId ;
16
28
fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
@@ -38,8 +50,9 @@ impl<'tcx> RustcInternal<'tcx> for GenericArgKind {
38
50
39
51
impl < ' tcx > RustcInternal < ' tcx > for Region {
40
52
type T = rustc_ty:: Region < ' tcx > ;
41
- fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
42
- todo ! ( )
53
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
54
+ // Cannot recover region. Use erased instead.
55
+ tables. tcx . lifetimes . re_erased
43
56
}
44
57
}
45
58
@@ -65,3 +78,118 @@ impl<'tcx> RustcInternal<'tcx> for Const {
65
78
tables. constants [ self . id ]
66
79
}
67
80
}
81
+
82
+ impl < ' tcx > RustcInternal < ' tcx > for MonoItem {
83
+ type T = rustc_middle:: mir:: mono:: MonoItem < ' tcx > ;
84
+
85
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
86
+ use rustc_middle:: mir:: mono as rustc_mono;
87
+ match self {
88
+ MonoItem :: Fn ( instance) => rustc_mono:: MonoItem :: Fn ( instance. internal ( tables) ) ,
89
+ MonoItem :: Static ( def) => rustc_mono:: MonoItem :: Static ( def. internal ( tables) ) ,
90
+ MonoItem :: GlobalAsm ( _) => {
91
+ unimplemented ! ( )
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ impl < ' tcx > RustcInternal < ' tcx > for Instance {
98
+ type T = rustc_ty:: Instance < ' tcx > ;
99
+
100
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
101
+ tables. instances [ self . def ]
102
+ }
103
+ }
104
+
105
+ impl < ' tcx > RustcInternal < ' tcx > for StaticDef {
106
+ type T = rustc_span:: def_id:: DefId ;
107
+
108
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
109
+ self . 0 . internal ( tables)
110
+ }
111
+ }
112
+
113
+ #[ allow( rustc:: usage_of_qualified_ty) ]
114
+ impl < ' tcx , T > RustcInternal < ' tcx > for Binder < T >
115
+ where
116
+ T : RustcInternal < ' tcx > ,
117
+ T :: T : rustc_ty:: TypeVisitable < rustc_ty:: TyCtxt < ' tcx > > ,
118
+ {
119
+ type T = rustc_ty:: Binder < ' tcx , T :: T > ;
120
+
121
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
122
+ rustc_ty:: Binder :: bind_with_vars (
123
+ self . value . internal ( tables) ,
124
+ tables. tcx . mk_bound_variable_kinds_from_iter (
125
+ self . bound_vars . iter ( ) . map ( |bound| bound. internal ( tables) ) ,
126
+ ) ,
127
+ )
128
+ }
129
+ }
130
+
131
+ impl < ' tcx > RustcInternal < ' tcx > for BoundVariableKind {
132
+ type T = rustc_ty:: BoundVariableKind ;
133
+
134
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
135
+ match self {
136
+ BoundVariableKind :: Ty ( kind) => rustc_ty:: BoundVariableKind :: Ty ( match kind {
137
+ BoundTyKind :: Anon => rustc_ty:: BoundTyKind :: Anon ,
138
+ BoundTyKind :: Param ( def, symbol) => {
139
+ rustc_ty:: BoundTyKind :: Param ( def. 0 . internal ( tables) , Symbol :: intern ( & symbol) )
140
+ }
141
+ } ) ,
142
+ BoundVariableKind :: Region ( kind) => rustc_ty:: BoundVariableKind :: Region ( match kind {
143
+ BoundRegionKind :: BrAnon => rustc_ty:: BoundRegionKind :: BrAnon ,
144
+ BoundRegionKind :: BrNamed ( def, symbol) => rustc_ty:: BoundRegionKind :: BrNamed (
145
+ def. 0 . internal ( tables) ,
146
+ Symbol :: intern ( & symbol) ,
147
+ ) ,
148
+ BoundRegionKind :: BrEnv => rustc_ty:: BoundRegionKind :: BrEnv ,
149
+ } ) ,
150
+ BoundVariableKind :: Const => rustc_ty:: BoundVariableKind :: Const ,
151
+ }
152
+ }
153
+ }
154
+
155
+ impl < ' tcx > RustcInternal < ' tcx > for TraitRef {
156
+ type T = rustc_ty:: TraitRef < ' tcx > ;
157
+
158
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
159
+ rustc_ty:: TraitRef :: new (
160
+ tables. tcx ,
161
+ self . def_id . 0 . internal ( tables) ,
162
+ self . args ( ) . internal ( tables) ,
163
+ )
164
+ }
165
+ }
166
+
167
+ impl < ' tcx > RustcInternal < ' tcx > for AllocId {
168
+ type T = rustc_middle:: mir:: interpret:: AllocId ;
169
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
170
+ tables. alloc_ids [ * self ]
171
+ }
172
+ }
173
+
174
+ impl < ' tcx > RustcInternal < ' tcx > for ClosureKind {
175
+ type T = rustc_ty:: ClosureKind ;
176
+
177
+ fn internal ( & self , _tables : & mut Tables < ' tcx > ) -> Self :: T {
178
+ match self {
179
+ ClosureKind :: Fn => rustc_ty:: ClosureKind :: Fn ,
180
+ ClosureKind :: FnMut => rustc_ty:: ClosureKind :: FnMut ,
181
+ ClosureKind :: FnOnce => rustc_ty:: ClosureKind :: FnOnce ,
182
+ }
183
+ }
184
+ }
185
+
186
+ impl < ' tcx , T > RustcInternal < ' tcx > for & T
187
+ where
188
+ T : RustcInternal < ' tcx > ,
189
+ {
190
+ type T = T :: T ;
191
+
192
+ fn internal ( & self , tables : & mut Tables < ' tcx > ) -> Self :: T {
193
+ ( * self ) . internal ( tables)
194
+ }
195
+ }
0 commit comments