@@ -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,18 +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
- 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 ( _) => { }
164
173
}
165
- ty:: ExistentialPredicate :: AutoTrait ( _) => { }
166
174
}
167
- }
168
- self . add_bound_computation ( computation ) ;
175
+ } ) ;
176
+
169
177
self . add_region ( r) ;
170
178
}
171
179
@@ -193,22 +201,21 @@ impl FlagComputation {
193
201
self . add_substs ( substs) ;
194
202
}
195
203
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
+ } ) ,
199
208
}
200
209
}
201
210
202
- fn add_predicate_kind ( & mut self , kind : & ty:: PredicateKind < ' _ > ) {
211
+ fn add_predicate_kind ( & mut self , kind : ty:: PredicateKind < ' _ > ) {
203
212
match kind {
204
213
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
+ } ) ;
210
217
}
211
- & ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
218
+ ty:: PredicateKind :: Atom ( atom) => self . add_predicate_atom ( atom) ,
212
219
}
213
220
}
214
221
@@ -264,15 +271,6 @@ impl FlagComputation {
264
271
}
265
272
}
266
273
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
-
276
274
fn add_region ( & mut self , r : ty:: Region < ' _ > ) {
277
275
self . add_flags ( r. type_flags ( ) ) ;
278
276
if let ty:: ReLateBound ( debruijn, _) = * r {
0 commit comments