@@ -671,17 +671,26 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
671
671
}
672
672
}
673
673
674
- /// Collects all the late-bound regions it finds into a hash set.
674
+ /// Collects all the late-bound regions at the innermost binding level
675
+ /// into a hash set.
675
676
struct LateBoundRegionsCollector {
676
- current_depth : u32 ,
677
+ current_index : ty :: DebruijnIndex ,
677
678
regions : FxHashSet < ty:: BoundRegion > ,
679
+
680
+ /// If true, we only want regions that are known to be
681
+ /// "constrained" when you equate this type with another type. In
682
+ /// partcular, if you have e.g. `&'a u32` and `&'b u32`, equating
683
+ /// them constraints `'a == 'b`. But if you have `<&'a u32 as
684
+ /// Trait>::Foo` and `<&'b u32 as Trait>::Foo`, normalizing those
685
+ /// types may mean that `'a` and `'b` don't appear in the results,
686
+ /// so they are not considered *constrained*.
678
687
just_constrained : bool ,
679
688
}
680
689
681
690
impl LateBoundRegionsCollector {
682
691
fn new ( just_constrained : bool ) -> Self {
683
692
LateBoundRegionsCollector {
684
- current_depth : 1 ,
693
+ current_index : ty :: DebruijnIndex :: INNERMOST ,
685
694
regions : FxHashSet ( ) ,
686
695
just_constrained,
687
696
}
@@ -690,9 +699,9 @@ impl LateBoundRegionsCollector {
690
699
691
700
impl < ' tcx > TypeVisitor < ' tcx > for LateBoundRegionsCollector {
692
701
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> bool {
693
- self . current_depth += 1 ;
702
+ self . current_index . shift_in ( 1 ) ;
694
703
let result = t. super_visit_with ( self ) ;
695
- self . current_depth -= 1 ;
704
+ self . current_index . shift_out ( 1 ) ;
696
705
result
697
706
}
698
707
@@ -712,7 +721,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
712
721
713
722
fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> bool {
714
723
match * r {
715
- ty:: ReLateBound ( debruijn, br) if debruijn. depth == self . current_depth => {
724
+ ty:: ReLateBound ( debruijn, br) if debruijn == self . current_index => {
716
725
self . regions . insert ( br) ;
717
726
}
718
727
_ => { }
0 commit comments