1
1
use crate :: ty:: subst:: { GenericArg , GenericArgKind } ;
2
2
use crate :: ty:: { self , InferConst , Ty , TypeFlags } ;
3
+ use std:: slice;
3
4
4
5
#[ derive( Debug ) ]
5
6
pub struct FlagComputation {
@@ -21,6 +22,12 @@ impl FlagComputation {
21
22
result
22
23
}
23
24
25
+ pub fn for_predicate ( kind : & ty:: PredicateKind < ' _ > ) -> FlagComputation {
26
+ let mut result = FlagComputation :: new ( ) ;
27
+ result. add_predicate_kind ( kind) ;
28
+ result
29
+ }
30
+
24
31
pub fn for_const ( c : & ty:: Const < ' _ > ) -> TypeFlags {
25
32
let mut result = FlagComputation :: new ( ) ;
26
33
result. add_const ( c) ;
@@ -32,7 +39,7 @@ impl FlagComputation {
32
39
}
33
40
34
41
/// indicates that `self` refers to something at binding level `binder`
35
- fn add_binder ( & mut self , binder : ty:: DebruijnIndex ) {
42
+ fn add_bound_var ( & mut self , binder : ty:: DebruijnIndex ) {
36
43
let exclusive_binder = binder. shifted_in ( 1 ) ;
37
44
self . add_exclusive_binder ( exclusive_binder) ;
38
45
}
@@ -46,7 +53,7 @@ impl FlagComputation {
46
53
47
54
/// Adds the flags/depth from a set of types that appear within the current type, but within a
48
55
/// region binder.
49
- fn add_bound_computation ( & mut self , computation : & FlagComputation ) {
56
+ fn add_bound_computation ( & mut self , computation : FlagComputation ) {
50
57
self . add_flags ( computation. flags ) ;
51
58
52
59
// The types that contributed to `computation` occurred within
@@ -84,15 +91,15 @@ impl FlagComputation {
84
91
& ty:: GeneratorWitness ( ref ts) => {
85
92
let mut computation = FlagComputation :: new ( ) ;
86
93
computation. add_tys ( & ts. skip_binder ( ) [ ..] ) ;
87
- self . add_bound_computation ( & computation) ;
94
+ self . add_bound_computation ( computation) ;
88
95
}
89
96
90
97
& ty:: Closure ( _, ref substs) => {
91
98
self . add_substs ( substs) ;
92
99
}
93
100
94
101
& ty:: Bound ( debruijn, _) => {
95
- self . add_binder ( debruijn) ;
102
+ self . add_bound_var ( debruijn) ;
96
103
}
97
104
98
105
& ty:: Placeholder ( ..) => {
@@ -133,12 +140,12 @@ impl FlagComputation {
133
140
ty:: ExistentialPredicate :: Projection ( p) => {
134
141
let mut proj_computation = FlagComputation :: new ( ) ;
135
142
proj_computation. add_existential_projection ( & p) ;
136
- self . add_bound_computation ( & proj_computation) ;
143
+ self . add_bound_computation ( proj_computation) ;
137
144
}
138
145
ty:: ExistentialPredicate :: AutoTrait ( _) => { }
139
146
}
140
147
}
141
- self . add_bound_computation ( & computation) ;
148
+ self . add_bound_computation ( computation) ;
142
149
self . add_region ( r) ;
143
150
}
144
151
@@ -172,6 +179,63 @@ impl FlagComputation {
172
179
}
173
180
}
174
181
182
+ fn add_predicate_kind ( & mut self , kind : & ty:: PredicateKind < ' _ > ) {
183
+ match kind {
184
+ ty:: PredicateKind :: Trait ( trait_pred, _constness) => {
185
+ let mut computation = FlagComputation :: new ( ) ;
186
+ computation. add_substs ( trait_pred. skip_binder ( ) . trait_ref . substs ) ;
187
+
188
+ self . add_bound_computation ( computation) ;
189
+ }
190
+ ty:: PredicateKind :: RegionOutlives ( poly_outlives) => {
191
+ let mut computation = FlagComputation :: new ( ) ;
192
+ let ty:: OutlivesPredicate ( a, b) = poly_outlives. skip_binder ( ) ;
193
+ computation. add_region ( a) ;
194
+ computation. add_region ( b) ;
195
+
196
+ self . add_bound_computation ( computation) ;
197
+ }
198
+ ty:: PredicateKind :: TypeOutlives ( poly_outlives) => {
199
+ let mut computation = FlagComputation :: new ( ) ;
200
+ let ty:: OutlivesPredicate ( ty, region) = poly_outlives. skip_binder ( ) ;
201
+ computation. add_ty ( ty) ;
202
+ computation. add_region ( region) ;
203
+
204
+ self . add_bound_computation ( computation) ;
205
+ }
206
+ ty:: PredicateKind :: Subtype ( poly_subtype) => {
207
+ let mut computation = FlagComputation :: new ( ) ;
208
+ let ty:: SubtypePredicate { a_is_expected : _, a, b } = poly_subtype. skip_binder ( ) ;
209
+ computation. add_ty ( a) ;
210
+ computation. add_ty ( b) ;
211
+
212
+ self . add_bound_computation ( computation) ;
213
+ }
214
+ ty:: PredicateKind :: Projection ( projection) => {
215
+ let mut computation = FlagComputation :: new ( ) ;
216
+ let ty:: ProjectionPredicate { projection_ty, ty } = projection. skip_binder ( ) ;
217
+ computation. add_projection_ty ( projection_ty) ;
218
+ computation. add_ty ( ty) ;
219
+
220
+ self . add_bound_computation ( computation) ;
221
+ }
222
+ ty:: PredicateKind :: WellFormed ( arg) => {
223
+ self . add_substs ( slice:: from_ref ( arg) ) ;
224
+ }
225
+ ty:: PredicateKind :: ObjectSafe ( _def_id) => { }
226
+ ty:: PredicateKind :: ClosureKind ( _def_id, substs, _kind) => {
227
+ self . add_substs ( substs) ;
228
+ }
229
+ ty:: PredicateKind :: ConstEvaluatable ( _def_id, substs) => {
230
+ self . add_substs ( substs) ;
231
+ }
232
+ ty:: PredicateKind :: ConstEquate ( expected, found) => {
233
+ self . add_const ( expected) ;
234
+ self . add_const ( found) ;
235
+ }
236
+ }
237
+ }
238
+
175
239
fn add_ty ( & mut self , ty : Ty < ' _ > ) {
176
240
self . add_flags ( ty. flags ) ;
177
241
self . add_exclusive_binder ( ty. outer_exclusive_binder ) ;
@@ -189,13 +253,13 @@ impl FlagComputation {
189
253
computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
190
254
computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
191
255
192
- self . add_bound_computation ( & computation) ;
256
+ self . add_bound_computation ( computation) ;
193
257
}
194
258
195
259
fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
196
260
self . add_flags ( r. type_flags ( ) ) ;
197
261
if let ty:: ReLateBound ( debruijn, _) = * r {
198
- self . add_binder ( debruijn) ;
262
+ self . add_bound_var ( debruijn) ;
199
263
}
200
264
}
201
265
@@ -214,7 +278,7 @@ impl FlagComputation {
214
278
}
215
279
}
216
280
ty:: ConstKind :: Bound ( debruijn, _) => {
217
- self . add_binder ( debruijn) ;
281
+ self . add_bound_var ( debruijn) ;
218
282
}
219
283
ty:: ConstKind :: Param ( _) => {
220
284
self . add_flags ( TypeFlags :: HAS_CT_PARAM ) ;
0 commit comments