@@ -253,13 +253,34 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
253
253
value. fold_with ( & mut RegionFolder :: new ( self , skipped_regions, & mut f) )
254
254
}
255
255
256
- pub fn for_each_free_region < T , F > ( self ,
257
- value : & T ,
258
- callback : F )
259
- where F : FnMut ( ty:: Region < ' tcx > ) ,
260
- T : TypeFoldable < ' tcx > ,
261
- {
262
- value. visit_with ( & mut RegionVisitor {
256
+ /// Invoke `callback` on every region appearing free in `value`.
257
+ pub fn for_each_free_region (
258
+ self ,
259
+ value : & impl TypeFoldable < ' tcx > ,
260
+ mut callback : impl FnMut ( ty:: Region < ' tcx > ) ,
261
+ ) {
262
+ self . any_free_region_meets ( value, |r| {
263
+ callback ( r) ;
264
+ false
265
+ } ) ;
266
+ }
267
+
268
+ /// True if `callback` returns true for every region appearing free in `value`.
269
+ pub fn all_free_regions_meet (
270
+ self ,
271
+ value : & impl TypeFoldable < ' tcx > ,
272
+ mut callback : impl FnMut ( ty:: Region < ' tcx > ) -> bool ,
273
+ ) -> bool {
274
+ !self . any_free_region_meets ( value, |r| !callback ( r) )
275
+ }
276
+
277
+ /// True if `callback` returns true for some region appearing free in `value`.
278
+ pub fn any_free_region_meets (
279
+ self ,
280
+ value : & impl TypeFoldable < ' tcx > ,
281
+ callback : impl FnMut ( ty:: Region < ' tcx > ) -> bool ,
282
+ ) -> bool {
283
+ return value. visit_with ( & mut RegionVisitor {
263
284
outer_index : ty:: INNERMOST ,
264
285
callback
265
286
} ) ;
@@ -287,25 +308,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
287
308
}
288
309
289
310
impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < F >
290
- where F : FnMut ( ty:: Region < ' tcx > )
311
+ where F : FnMut ( ty:: Region < ' tcx > ) -> bool
291
312
{
292
313
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> bool {
293
314
self . outer_index . shift_in ( 1 ) ;
294
- t. skip_binder ( ) . visit_with ( self ) ;
315
+ let result = t. skip_binder ( ) . visit_with ( self ) ;
295
316
self . outer_index . shift_out ( 1 ) ;
296
-
297
- false // keep visiting
317
+ result
298
318
}
299
319
300
320
fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> bool {
301
321
match * r {
302
322
ty:: ReLateBound ( debruijn, _) if debruijn < self . outer_index => {
303
- /* ignore bound regions */
323
+ false // ignore bound regions, keep visiting
304
324
}
305
325
_ => ( self . callback ) ( r) ,
306
326
}
307
-
308
- false // keep visiting
309
327
}
310
328
}
311
329
}
0 commit comments