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
self . add_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
97
104
}
98
105
@@ -134,12 +141,12 @@ impl FlagComputation {
134
141
ty:: ExistentialPredicate :: Projection ( p) => {
135
142
let mut proj_computation = FlagComputation :: new ( ) ;
136
143
proj_computation. add_existential_projection ( & p) ;
137
- self . add_bound_computation ( & proj_computation) ;
144
+ self . add_bound_computation ( proj_computation) ;
138
145
}
139
146
ty:: ExistentialPredicate :: AutoTrait ( _) => { }
140
147
}
141
148
}
142
- self . add_bound_computation ( & computation) ;
149
+ self . add_bound_computation ( computation) ;
143
150
self . add_region ( r) ;
144
151
}
145
152
@@ -173,6 +180,63 @@ impl FlagComputation {
173
180
}
174
181
}
175
182
183
+ fn add_predicate_kind ( & mut self , kind : & ty:: PredicateKind < ' _ > ) {
184
+ match kind {
185
+ ty:: PredicateKind :: Trait ( trait_pred, _constness) => {
186
+ let mut computation = FlagComputation :: new ( ) ;
187
+ computation. add_substs ( trait_pred. skip_binder ( ) . trait_ref . substs ) ;
188
+
189
+ self . add_bound_computation ( computation) ;
190
+ }
191
+ ty:: PredicateKind :: RegionOutlives ( poly_outlives) => {
192
+ let mut computation = FlagComputation :: new ( ) ;
193
+ let ty:: OutlivesPredicate ( a, b) = poly_outlives. skip_binder ( ) ;
194
+ computation. add_region ( a) ;
195
+ computation. add_region ( b) ;
196
+
197
+ self . add_bound_computation ( computation) ;
198
+ }
199
+ ty:: PredicateKind :: TypeOutlives ( poly_outlives) => {
200
+ let mut computation = FlagComputation :: new ( ) ;
201
+ let ty:: OutlivesPredicate ( ty, region) = poly_outlives. skip_binder ( ) ;
202
+ computation. add_ty ( ty) ;
203
+ computation. add_region ( region) ;
204
+
205
+ self . add_bound_computation ( computation) ;
206
+ }
207
+ ty:: PredicateKind :: Subtype ( poly_subtype) => {
208
+ let mut computation = FlagComputation :: new ( ) ;
209
+ let ty:: SubtypePredicate { a_is_expected : _, a, b } = poly_subtype. skip_binder ( ) ;
210
+ computation. add_ty ( a) ;
211
+ computation. add_ty ( b) ;
212
+
213
+ self . add_bound_computation ( computation) ;
214
+ }
215
+ ty:: PredicateKind :: Projection ( projection) => {
216
+ let mut computation = FlagComputation :: new ( ) ;
217
+ let ty:: ProjectionPredicate { projection_ty, ty } = projection. skip_binder ( ) ;
218
+ computation. add_projection_ty ( projection_ty) ;
219
+ computation. add_ty ( ty) ;
220
+
221
+ self . add_bound_computation ( computation) ;
222
+ }
223
+ ty:: PredicateKind :: WellFormed ( arg) => {
224
+ self . add_substs ( slice:: from_ref ( arg) ) ;
225
+ }
226
+ ty:: PredicateKind :: ObjectSafe ( _def_id) => { }
227
+ ty:: PredicateKind :: ClosureKind ( _def_id, substs, _kind) => {
228
+ self . add_substs ( substs) ;
229
+ }
230
+ ty:: PredicateKind :: ConstEvaluatable ( _def_id, substs) => {
231
+ self . add_substs ( substs) ;
232
+ }
233
+ ty:: PredicateKind :: ConstEquate ( expected, found) => {
234
+ self . add_const ( expected) ;
235
+ self . add_const ( found) ;
236
+ }
237
+ }
238
+ }
239
+
176
240
fn add_ty ( & mut self , ty : Ty < ' _ > ) {
177
241
self . add_flags ( ty. flags ) ;
178
242
self . add_exclusive_binder ( ty. outer_exclusive_binder ) ;
@@ -190,13 +254,13 @@ impl FlagComputation {
190
254
computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
191
255
computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
192
256
193
- self . add_bound_computation ( & computation) ;
257
+ self . add_bound_computation ( computation) ;
194
258
}
195
259
196
260
fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
197
261
self . add_flags ( r. type_flags ( ) ) ;
198
262
if let ty:: ReLateBound ( debruijn, _) = * r {
199
- self . add_binder ( debruijn) ;
263
+ self . add_bound_var ( debruijn) ;
200
264
}
201
265
}
202
266
@@ -215,7 +279,7 @@ impl FlagComputation {
215
279
}
216
280
}
217
281
ty:: ConstKind :: Bound ( debruijn, _) => {
218
- self . add_binder ( debruijn) ;
282
+ self . add_bound_var ( debruijn) ;
219
283
self . add_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
220
284
}
221
285
ty:: ConstKind :: Param ( _) => {
0 commit comments