Skip to content

Commit 06b2a3f

Browse files
nikomatsakiscsmoe
andcommitted
convert LateBoundRegionsCollector to track a debruijn index
Co-authored-by: csmoe <[email protected]>
1 parent 4aeb6ef commit 06b2a3f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/librustc/ty/fold.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,26 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
671671
}
672672
}
673673

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.
675676
struct LateBoundRegionsCollector {
676-
current_depth: u32,
677+
current_index: ty::DebruijnIndex,
677678
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*.
678687
just_constrained: bool,
679688
}
680689

681690
impl LateBoundRegionsCollector {
682691
fn new(just_constrained: bool) -> Self {
683692
LateBoundRegionsCollector {
684-
current_depth: 1,
693+
current_index: ty::DebruijnIndex::INNERMOST,
685694
regions: FxHashSet(),
686695
just_constrained,
687696
}
@@ -690,9 +699,9 @@ impl LateBoundRegionsCollector {
690699

691700
impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
692701
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
693-
self.current_depth += 1;
702+
self.current_index.shift_in(1);
694703
let result = t.super_visit_with(self);
695-
self.current_depth -= 1;
704+
self.current_index.shift_out(1);
696705
result
697706
}
698707

@@ -712,7 +721,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
712721

713722
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
714723
match *r {
715-
ty::ReLateBound(debruijn, br) if debruijn.depth == self.current_depth => {
724+
ty::ReLateBound(debruijn, br) if debruijn == self.current_index => {
716725
self.regions.insert(br);
717726
}
718727
_ => { }

0 commit comments

Comments
 (0)