@@ -63,20 +63,22 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
63
63
self . super_visit_with ( visitor)
64
64
}
65
65
66
- fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
67
- self . visit_with ( & mut HasEscapingRegionsVisitor { depth : depth } )
68
- }
69
-
70
66
/// True if `self` has any late-bound regions that are either
71
67
/// bound by `binder` or bound by some binder outside of `binder`.
72
68
/// If `binder` is `ty::DebruijnIndex::INNERMOST`, this indicates whether
73
69
/// there are any late-bound regions that appear free.
74
- fn has_regions_bound_by_or_escaping ( & self , binder : ty:: DebruijnIndex ) -> bool {
75
- self . has_regions_escaping_depth ( binder. depth - 1 )
70
+ fn has_regions_bound_at_or_above ( & self , binder : ty:: DebruijnIndex ) -> bool {
71
+ self . visit_with ( & mut HasEscapingRegionsVisitor { outer_index : binder } )
72
+ }
73
+
74
+ /// True if this `self` has any regions that escape `binder` (and
75
+ /// hence are not bound by it).
76
+ fn has_regions_bound_above ( & self , binder : ty:: DebruijnIndex ) -> bool {
77
+ self . has_regions_bound_at_or_above ( binder. shifted_in ( 1 ) )
76
78
}
77
79
78
80
fn has_escaping_regions ( & self ) -> bool {
79
- self . has_regions_escaping_depth ( 0 )
81
+ self . has_regions_bound_at_or_above ( ty :: DebruijnIndex :: INNERMOST )
80
82
}
81
83
82
84
fn has_type_flags ( & self , flags : TypeFlags ) -> bool {
@@ -523,7 +525,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionReplacer<'a, 'gcx, 'tcx> {
523
525
}
524
526
525
527
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
526
- if !t. has_regions_bound_by_or_escaping ( self . current_index ) {
528
+ if !t. has_regions_bound_at_or_above ( self . current_index ) {
527
529
return t;
528
530
}
529
531
@@ -623,23 +625,32 @@ pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
623
625
/// represent the scope to which it is attached, etc. An escaping region represents a bound region
624
626
/// for which this processing has not yet been done.
625
627
struct HasEscapingRegionsVisitor {
626
- depth : u32 ,
628
+ /// Anything bound by `outer_index` or "above" is escaping
629
+ outer_index : ty:: DebruijnIndex ,
627
630
}
628
631
629
632
impl < ' tcx > TypeVisitor < ' tcx > for HasEscapingRegionsVisitor {
630
633
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> bool {
631
- self . depth += 1 ;
634
+ self . outer_index . shift_in ( 1 ) ;
632
635
let result = t. super_visit_with ( self ) ;
633
- self . depth -= 1 ;
636
+ self . outer_index . shift_out ( 1 ) ;
634
637
result
635
638
}
636
639
637
640
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
638
- t. region_depth > self . depth
641
+ // If the outer-exclusive-binder is *strictly greater* than
642
+ // `outer_index`, that means that `t` contains some content
643
+ // bound at `outer_index` or above (because
644
+ // `outer_exclusive_binder` is always 1 higher than the
645
+ // content in `t`). Therefore, `t` has some escaping regions.
646
+ t. outer_exclusive_binder > self . outer_index
639
647
}
640
648
641
649
fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> bool {
642
- r. escapes_depth ( self . depth )
650
+ // If the region is bound by `outer_index` or anything outside
651
+ // of outer index, then it escapes the binders we have
652
+ // visited.
653
+ r. bound_at_or_above_binder ( self . outer_index )
643
654
}
644
655
}
645
656
0 commit comments