@@ -22,7 +22,7 @@ impl FlagComputation {
22
22
result
23
23
}
24
24
25
- pub fn for_predicate ( kind : & ty:: PredicateKind < ' _ > ) -> FlagComputation {
25
+ pub fn for_predicate ( kind : ty:: PredicateKind < ' _ > ) -> FlagComputation {
26
26
let mut result = FlagComputation :: new ( ) ;
27
27
result. add_predicate_kind ( kind) ;
28
28
result
@@ -53,7 +53,14 @@ impl FlagComputation {
53
53
54
54
/// Adds the flags/depth from a set of types that appear within the current type, but within a
55
55
/// 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
+
57
64
self . add_flags ( computation. flags ) ;
58
65
59
66
// The types that contributed to `computation` occurred within
@@ -101,9 +108,7 @@ impl FlagComputation {
101
108
}
102
109
103
110
& 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) ) ;
107
112
}
108
113
109
114
& ty:: Closure ( _, substs) => {
@@ -154,20 +159,21 @@ impl FlagComputation {
154
159
self . add_substs ( substs) ;
155
160
}
156
161
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
- let mut proj_computation = FlagComputation :: new ( ) ;
164
- proj_computation. add_existential_projection ( & p) ;
165
- self . add_bound_computation ( proj_computation) ;
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 ( _) => { }
166
173
}
167
- ty:: ExistentialPredicate :: AutoTrait ( _) => { }
168
174
}
169
- }
170
- self . add_bound_computation ( computation ) ;
175
+ } ) ;
176
+
171
177
self . add_region ( r) ;
172
178
}
173
179
@@ -195,22 +201,21 @@ impl FlagComputation {
195
201
self . add_substs ( substs) ;
196
202
}
197
203
198
- & ty:: FnPtr ( f) => {
199
- self . add_fn_sig ( f) ;
200
- }
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
+ } ) ,
201
208
}
202
209
}
203
210
204
- fn add_predicate_kind ( & mut self , kind : & ty:: PredicateKind < ' _ > ) {
211
+ fn add_predicate_kind ( & mut self , kind : ty:: PredicateKind < ' _ > ) {
205
212
match kind {
206
213
ty:: PredicateKind :: ForAll ( binder) => {
207
- let mut computation = FlagComputation :: new ( ) ;
208
-
209
- computation. add_predicate_atom ( binder. skip_binder ( ) ) ;
210
-
211
- self . add_bound_computation ( computation) ;
214
+ self . bound_computation ( binder, |computation, atom| {
215
+ computation. add_predicate_atom ( atom)
216
+ } ) ;
212
217
}
213
- & ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
218
+ ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
214
219
}
215
220
}
216
221
@@ -266,15 +271,6 @@ impl FlagComputation {
266
271
}
267
272
}
268
273
269
- fn add_fn_sig ( & mut self , fn_sig : ty:: PolyFnSig < ' _ > ) {
270
- let mut computation = FlagComputation :: new ( ) ;
271
-
272
- computation. add_tys ( fn_sig. skip_binder ( ) . inputs ( ) ) ;
273
- computation. add_ty ( fn_sig. skip_binder ( ) . output ( ) ) ;
274
-
275
- self . add_bound_computation ( computation) ;
276
- }
277
-
278
274
fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
279
275
self . add_flags ( r. type_flags ( ) ) ;
280
276
if let ty:: ReLateBound ( debruijn, _) = * r {
0 commit comments