Skip to content

Commit

Permalink
convert LateBoundRegionsCollector to track a debruijn index
Browse files Browse the repository at this point in the history
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
  • Loading branch information
nikomatsakis and csmoe committed May 28, 2018
1 parent 4aeb6ef commit 06b2a3f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/librustc/ty/fold.rs
Expand Up @@ -671,17 +671,26 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
}
}

/// Collects all the late-bound regions it finds into a hash set.
/// Collects all the late-bound regions at the innermost binding level
/// into a hash set.
struct LateBoundRegionsCollector {
current_depth: u32,
current_index: ty::DebruijnIndex,
regions: FxHashSet<ty::BoundRegion>,

/// If true, we only want regions that are known to be
/// "constrained" when you equate this type with another type. In
/// partcular, if you have e.g. `&'a u32` and `&'b u32`, equating
/// them constraints `'a == 'b`. But if you have `<&'a u32 as
/// Trait>::Foo` and `<&'b u32 as Trait>::Foo`, normalizing those
/// types may mean that `'a` and `'b` don't appear in the results,
/// so they are not considered *constrained*.
just_constrained: bool,
}

impl LateBoundRegionsCollector {
fn new(just_constrained: bool) -> Self {
LateBoundRegionsCollector {
current_depth: 1,
current_index: ty::DebruijnIndex::INNERMOST,
regions: FxHashSet(),
just_constrained,
}
Expand All @@ -690,9 +699,9 @@ impl LateBoundRegionsCollector {

impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
self.current_depth += 1;
self.current_index.shift_in(1);
let result = t.super_visit_with(self);
self.current_depth -= 1;
self.current_index.shift_out(1);
result
}

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

fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
match *r {
ty::ReLateBound(debruijn, br) if debruijn.depth == self.current_depth => {
ty::ReLateBound(debruijn, br) if debruijn == self.current_index => {
self.regions.insert(br);
}
_ => { }
Expand Down

0 comments on commit 06b2a3f

Please sign in to comment.