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 }
97104
98105 & ty:: Placeholder ( ..) => {
@@ -133,12 +140,12 @@ impl FlagComputation {
133140 ty:: ExistentialPredicate :: Projection ( p) => {
134141 let mut proj_computation = FlagComputation :: new ( ) ;
135142 proj_computation. add_existential_projection ( & p) ;
136- self . add_bound_computation ( & proj_computation) ;
143+ self . add_bound_computation ( proj_computation) ;
137144 }
138145 ty:: ExistentialPredicate :: AutoTrait ( _) => { }
139146 }
140147 }
141- self . add_bound_computation ( & computation) ;
148+ self . add_bound_computation ( computation) ;
142149 self . add_region ( r) ;
143150 }
144151
@@ -172,6 +179,63 @@ impl FlagComputation {
172179 }
173180 }
174181
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+
175239 fn add_ty ( & mut self , ty : Ty < ' _ > ) {
176240 self . add_flags ( ty. flags ) ;
177241 self . add_exclusive_binder ( ty. outer_exclusive_binder ) ;
@@ -189,13 +253,13 @@ impl FlagComputation {
189253 computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
190254 computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
191255
192- self . add_bound_computation ( & computation) ;
256+ self . add_bound_computation ( computation) ;
193257 }
194258
195259 fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
196260 self . add_flags ( r. type_flags ( ) ) ;
197261 if let ty:: ReLateBound ( debruijn, _) = * r {
198- self . add_binder ( debruijn) ;
262+ self . add_bound_var ( debruijn) ;
199263 }
200264 }
201265
@@ -214,7 +278,7 @@ impl FlagComputation {
214278 }
215279 }
216280 ty:: ConstKind :: Bound ( debruijn, _) => {
217- self . add_binder ( debruijn) ;
281+ self . add_bound_var ( debruijn) ;
218282 }
219283 ty:: ConstKind :: Param ( _) => {
220284 self . add_flags ( TypeFlags :: HAS_CT_PARAM ) ;
0 commit comments