convert LateBoundRegionsCollector
to track a debruijn index
Co-authored-by: csmoe <35686186+csmoe@users.noreply.github.com>
This commit is contained in:
parent
4aeb6efb6d
commit
06b2a3fbdb
1 changed files with 15 additions and 6 deletions
|
@ -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 {
|
struct LateBoundRegionsCollector {
|
||||||
current_depth: u32,
|
current_index: ty::DebruijnIndex,
|
||||||
regions: FxHashSet<ty::BoundRegion>,
|
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,
|
just_constrained: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LateBoundRegionsCollector {
|
impl LateBoundRegionsCollector {
|
||||||
fn new(just_constrained: bool) -> Self {
|
fn new(just_constrained: bool) -> Self {
|
||||||
LateBoundRegionsCollector {
|
LateBoundRegionsCollector {
|
||||||
current_depth: 1,
|
current_index: ty::DebruijnIndex::INNERMOST,
|
||||||
regions: FxHashSet(),
|
regions: FxHashSet(),
|
||||||
just_constrained,
|
just_constrained,
|
||||||
}
|
}
|
||||||
|
@ -690,9 +699,9 @@ impl LateBoundRegionsCollector {
|
||||||
|
|
||||||
impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
|
impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
|
||||||
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
|
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);
|
let result = t.super_visit_with(self);
|
||||||
self.current_depth -= 1;
|
self.current_index.shift_out(1);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,7 +721,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
|
||||||
|
|
||||||
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
|
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
|
||||||
match *r {
|
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);
|
self.regions.insert(br);
|
||||||
}
|
}
|
||||||
_ => { }
|
_ => { }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue