Skip to content

Commit 34c9ae7

Browse files
nikomatsakiscsmoe
andcommitted
refactor resolve_lifetime to track outer-index, not depth
Co-authored-by: csmoe <[email protected]>
1 parent f965b79 commit 34c9ae7

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/librustc/middle/resolve_lifetime.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,15 @@ impl Region {
133133
}
134134
}
135135

136-
fn from_depth(self, depth: u32) -> Region {
136+
fn shifted_out_to_binder(self, binder: ty::DebruijnIndex) -> Region {
137137
match self {
138138
Region::LateBound(debruijn, id, origin) => Region::LateBound(
139-
ty::DebruijnIndex {
140-
depth: debruijn.depth - (depth - 1),
141-
},
139+
debruijn.shifted_out_to_binder(binder),
142140
id,
143141
origin,
144142
),
145143
Region::LateBoundAnon(debruijn, index) => Region::LateBoundAnon(
146-
ty::DebruijnIndex {
147-
depth: debruijn.depth - (depth - 1),
148-
},
144+
debruijn.shifted_out_to_binder(binder),
149145
index,
150146
),
151147
_ => self,
@@ -1858,7 +1854,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
18581854
.map(|(i, input)| {
18591855
let mut gather = GatherLifetimes {
18601856
map: self.map,
1861-
binder_depth: 1,
1857+
outer_index: ty::DebruijnIndex::INNERMOST,
18621858
have_bound_regions: false,
18631859
lifetimes: FxHashSet(),
18641860
};
@@ -1899,7 +1895,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
18991895

19001896
struct GatherLifetimes<'a> {
19011897
map: &'a NamedRegionMap,
1902-
binder_depth: u32,
1898+
outer_index: ty::DebruijnIndex,
19031899
have_bound_regions: bool,
19041900
lifetimes: FxHashSet<Region>,
19051901
}
@@ -1911,7 +1907,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19111907

19121908
fn visit_ty(&mut self, ty: &hir::Ty) {
19131909
if let hir::TyBareFn(_) = ty.node {
1914-
self.binder_depth += 1;
1910+
self.outer_index.shift_in(1);
19151911
}
19161912
if let hir::TyTraitObject(ref bounds, ref lifetime) = ty.node {
19171913
for bound in bounds {
@@ -1927,7 +1923,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19271923
intravisit::walk_ty(self, ty);
19281924
}
19291925
if let hir::TyBareFn(_) = ty.node {
1930-
self.binder_depth -= 1;
1926+
self.outer_index.shift_out(1);
19311927
}
19321928
}
19331929

@@ -1946,22 +1942,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19461942
trait_ref: &hir::PolyTraitRef,
19471943
modifier: hir::TraitBoundModifier,
19481944
) {
1949-
self.binder_depth += 1;
1945+
self.outer_index.shift_in(1);
19501946
intravisit::walk_poly_trait_ref(self, trait_ref, modifier);
1951-
self.binder_depth -= 1;
1947+
self.outer_index.shift_out(1);
19521948
}
19531949

19541950
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
19551951
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) {
19561952
match lifetime {
19571953
Region::LateBound(debruijn, _, _) | Region::LateBoundAnon(debruijn, _)
1958-
if debruijn.depth < self.binder_depth =>
1954+
if debruijn < self.outer_index =>
19591955
{
19601956
self.have_bound_regions = true;
19611957
}
19621958
_ => {
19631959
self.lifetimes
1964-
.insert(lifetime.from_depth(self.binder_depth));
1960+
.insert(lifetime.shifted_out_to_binder(self.outer_index));
19651961
}
19661962
}
19671963
}

0 commit comments

Comments
 (0)