11use crate :: ty:: subst:: { GenericArg , GenericArgKind } ;
22use crate :: ty:: { self , InferConst , Ty , TypeFlags } ;
3+ use std:: slice;
34
45#[ derive( Debug ) ]
56pub struct FlagComputation {
@@ -21,6 +22,12 @@ impl FlagComputation {
2122 result
2223 }
2324
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+
2431 pub fn for_const ( c : & ty:: Const < ' _ > ) -> TypeFlags {
2532 let mut result = FlagComputation :: new ( ) ;
2633 result. add_const ( c) ;
@@ -32,7 +39,7 @@ impl FlagComputation {
3239 }
3340
3441 /// 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 ) {
3643 let exclusive_binder = binder. shifted_in ( 1 ) ;
3744 self . add_exclusive_binder ( exclusive_binder) ;
3845 }
@@ -46,7 +53,7 @@ impl FlagComputation {
4653
4754 /// Adds the flags/depth from a set of types that appear within the current type, but within a
4855 /// region binder.
49- fn add_bound_computation ( & mut self , computation : & FlagComputation ) {
56+ fn add_bound_computation ( & mut self , computation : FlagComputation ) {
5057 self . add_flags ( computation. flags ) ;
5158
5259 // The types that contributed to `computation` occurred within
@@ -84,15 +91,15 @@ impl FlagComputation {
8491 & ty:: GeneratorWitness ( ref ts) => {
8592 let mut computation = FlagComputation :: new ( ) ;
8693 computation. add_tys ( & ts. skip_binder ( ) [ ..] ) ;
87- self . add_bound_computation ( & computation) ;
94+ self . add_bound_computation ( computation) ;
8895 }
8996
9097 & ty:: Closure ( _, ref substs) => {
9198 self . add_substs ( substs) ;
9299 }
93100
94101 & ty:: Bound ( debruijn, _) => {
95- self . add_binder ( debruijn) ;
102+ self . add_bound_var ( debruijn) ;
96103 self . add_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
97104 }
98105
@@ -134,12 +141,12 @@ impl FlagComputation {
134141 ty:: ExistentialPredicate :: Projection ( p) => {
135142 let mut proj_computation = FlagComputation :: new ( ) ;
136143 proj_computation. add_existential_projection ( & p) ;
137- self . add_bound_computation ( & proj_computation) ;
144+ self . add_bound_computation ( proj_computation) ;
138145 }
139146 ty:: ExistentialPredicate :: AutoTrait ( _) => { }
140147 }
141148 }
142- self . add_bound_computation ( & computation) ;
149+ self . add_bound_computation ( computation) ;
143150 self . add_region ( r) ;
144151 }
145152
@@ -173,6 +180,63 @@ impl FlagComputation {
173180 }
174181 }
175182
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+
176240 fn add_ty ( & mut self , ty : Ty < ' _ > ) {
177241 self . add_flags ( ty. flags ) ;
178242 self . add_exclusive_binder ( ty. outer_exclusive_binder ) ;
@@ -190,13 +254,13 @@ impl FlagComputation {
190254 computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
191255 computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
192256
193- self . add_bound_computation ( & computation) ;
257+ self . add_bound_computation ( computation) ;
194258 }
195259
196260 fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
197261 self . add_flags ( r. type_flags ( ) ) ;
198262 if let ty:: ReLateBound ( debruijn, _) = * r {
199- self . add_binder ( debruijn) ;
263+ self . add_bound_var ( debruijn) ;
200264 }
201265 }
202266
@@ -215,7 +279,7 @@ impl FlagComputation {
215279 }
216280 }
217281 ty:: ConstKind :: Bound ( debruijn, _) => {
218- self . add_binder ( debruijn) ;
282+ self . add_bound_var ( debruijn) ;
219283 self . add_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
220284 }
221285 ty:: ConstKind :: Param ( _) => {
0 commit comments