@@ -22,7 +22,7 @@ impl FlagComputation {
2222 result
2323 }
2424
25- pub fn for_predicate ( kind : & ty:: PredicateKind < ' _ > ) -> FlagComputation {
25+ pub fn for_predicate ( kind : ty:: PredicateKind < ' _ > ) -> FlagComputation {
2626 let mut result = FlagComputation :: new ( ) ;
2727 result. add_predicate_kind ( kind) ;
2828 result
@@ -53,7 +53,14 @@ impl FlagComputation {
5353
5454 /// Adds the flags/depth from a set of types that appear within the current type, but within a
5555 /// region binder.
56- fn add_bound_computation ( & mut self , computation : FlagComputation ) {
56+ fn bound_computation < T , F > ( & mut self , value : ty:: Binder < T > , f : F )
57+ where
58+ F : FnOnce ( & mut Self , T ) ,
59+ {
60+ let mut computation = FlagComputation :: new ( ) ;
61+
62+ f ( & mut computation, value. skip_binder ( ) ) ;
63+
5764 self . add_flags ( computation. flags ) ;
5865
5966 // The types that contributed to `computation` occurred within
@@ -101,9 +108,7 @@ impl FlagComputation {
101108 }
102109
103110 & ty:: GeneratorWitness ( ts) => {
104- let mut computation = FlagComputation :: new ( ) ;
105- computation. add_tys ( ts. skip_binder ( ) ) ;
106- self . add_bound_computation ( computation) ;
111+ self . bound_computation ( ts, |flags, ts| flags. add_tys ( ts) ) ;
107112 }
108113
109114 & ty:: Closure ( _, substs) => {
@@ -154,18 +159,21 @@ impl FlagComputation {
154159 self . add_substs ( substs) ;
155160 }
156161
157- & ty:: Dynamic ( ref obj, r) => {
158- let mut computation = FlagComputation :: new ( ) ;
159- for predicate in obj. skip_binder ( ) . iter ( ) {
160- match predicate {
161- ty:: ExistentialPredicate :: Trait ( tr) => computation. add_substs ( tr. substs ) ,
162- ty:: ExistentialPredicate :: Projection ( p) => {
163- computation. add_existential_projection ( & p) ;
162+ & ty:: Dynamic ( obj, r) => {
163+ self . bound_computation ( obj, |computation, obj| {
164+ for predicate in obj. iter ( ) {
165+ match predicate {
166+ ty:: ExistentialPredicate :: Trait ( tr) => {
167+ computation. add_substs ( tr. substs )
168+ }
169+ ty:: ExistentialPredicate :: Projection ( p) => {
170+ computation. add_existential_projection ( & p) ;
171+ }
172+ ty:: ExistentialPredicate :: AutoTrait ( _) => { }
164173 }
165- ty:: ExistentialPredicate :: AutoTrait ( _) => { }
166174 }
167- }
168- self . add_bound_computation ( computation ) ;
175+ } ) ;
176+
169177 self . add_region ( r) ;
170178 }
171179
@@ -193,22 +201,21 @@ impl FlagComputation {
193201 self . add_substs ( substs) ;
194202 }
195203
196- & ty:: FnPtr ( f) => {
197- self . add_fn_sig ( f) ;
198- }
204+ & ty:: FnPtr ( fn_sig) => self . bound_computation ( fn_sig, |computation, fn_sig| {
205+ computation. add_tys ( fn_sig. inputs ( ) ) ;
206+ computation. add_ty ( fn_sig. output ( ) ) ;
207+ } ) ,
199208 }
200209 }
201210
202- fn add_predicate_kind ( & mut self , kind : & ty:: PredicateKind < ' _ > ) {
211+ fn add_predicate_kind ( & mut self , kind : ty:: PredicateKind < ' _ > ) {
203212 match kind {
204213 ty:: PredicateKind :: ForAll ( binder) => {
205- let mut computation = FlagComputation :: new ( ) ;
206-
207- computation. add_predicate_atom ( binder. skip_binder ( ) ) ;
208-
209- self . add_bound_computation ( computation) ;
214+ self . bound_computation ( binder, |computation, atom| {
215+ computation. add_predicate_atom ( atom)
216+ } ) ;
210217 }
211- & ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
218+ ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
212219 }
213220 }
214221
@@ -264,15 +271,6 @@ impl FlagComputation {
264271 }
265272 }
266273
267- fn add_fn_sig ( & mut self , fn_sig : ty:: PolyFnSig < ' _ > ) {
268- let mut computation = FlagComputation :: new ( ) ;
269-
270- computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
271- computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
272-
273- self . add_bound_computation ( computation) ;
274- }
275-
276274 fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
277275 self . add_flags ( r. type_flags ( ) ) ;
278276 if let ty:: ReLateBound ( debruijn, _) = * r {
0 commit comments