diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-05-28 10:24:01 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-05-28 19:47:04 -0400 |
| commit | 06b2a3fbdbfdf6cc13a9eae74966a966cfde7aaf (patch) | |
| tree | 12e6446d5e0f2de3f244b586ccad370b2529c35a | |
| parent | 4aeb6efb6d584ae7632787edff60f3d9e4eb7384 (diff) | |
| download | rust-06b2a3fbdbfdf6cc13a9eae74966a966cfde7aaf.tar.gz rust-06b2a3fbdbfdf6cc13a9eae74966a966cfde7aaf.zip | |
convert `LateBoundRegionsCollector` to track a debruijn index
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
| -rw-r--r-- | src/librustc/ty/fold.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 00fa1a54558..f1a7add784e 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -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, } @@ -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 } @@ -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); } _ => { } |
