Skip to content

Commit 8cdfe8c

Browse files
author
Alex Muscar
committed
Adjust type Debruijn depth calculations
1 parent 55a6c62 commit 8cdfe8c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/librustc/middle/resolve_lifetime.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ impl Region {
137137
match self {
138138
Region::LateBound(debruijn, id, origin) => Region::LateBound(
139139
ty::DebruijnIndex {
140-
depth: debruijn.depth - (depth - 1),
140+
depth: debruijn.depth - depth,
141141
},
142142
id,
143143
origin,
144144
),
145145
Region::LateBoundAnon(debruijn, index) => Region::LateBoundAnon(
146146
ty::DebruijnIndex {
147-
depth: debruijn.depth - (depth - 1),
147+
depth: debruijn.depth - depth,
148148
},
149149
index,
150150
),
@@ -1781,7 +1781,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17811781
.map(|(i, input)| {
17821782
let mut gather = GatherLifetimes {
17831783
map: self.map,
1784-
binder_depth: 1,
1784+
binder_depth: 0,
17851785
have_bound_regions: false,
17861786
lifetimes: FxHashSet(),
17871787
};

src/librustc/ty/fold.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'a, 'gcx, 'tcx> RegionFolder<'a, 'gcx, 'tcx> {
292292
RegionFolder {
293293
tcx,
294294
skipped_regions,
295-
current_depth: 1,
295+
current_depth: 0,
296296
fld_r,
297297
}
298298
}
@@ -460,7 +460,7 @@ impl<'a, 'gcx, 'tcx> RegionReplacer<'a, 'gcx, 'tcx> {
460460
{
461461
RegionReplacer {
462462
tcx,
463-
current_depth: 1,
463+
current_depth: 0,
464464
fld_r,
465465
map: BTreeMap::default()
466466
}
@@ -478,7 +478,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionReplacer<'a, 'gcx, 'tcx> {
478478
}
479479

480480
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
481-
if !t.has_regions_escaping_depth(self.current_depth-1) {
481+
if !t.has_regions_escaping_depth(self.current_depth) {
482482
return t;
483483
}
484484

@@ -635,7 +635,7 @@ struct LateBoundRegionsCollector {
635635
impl LateBoundRegionsCollector {
636636
fn new(just_constrained: bool) -> Self {
637637
LateBoundRegionsCollector {
638-
current_depth: 1,
638+
current_depth: 0,
639639
regions: FxHashSet(),
640640
just_constrained,
641641
}

src/librustc/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1187,11 +1187,11 @@ impl RegionKind {
11871187
}
11881188
}
11891189

1190-
/// Returns the depth of `self` from the (1-based) binding level `depth`
1190+
/// Returns the depth of `self` from the (0-based) binding level `depth`
11911191
pub fn from_depth(&self, depth: u32) -> RegionKind {
11921192
match *self {
11931193
ty::ReLateBound(debruijn, r) => ty::ReLateBound(DebruijnIndex {
1194-
depth: debruijn.depth - (depth - 1)
1194+
depth: debruijn.depth - depth
11951195
}, r),
11961196
r => r
11971197
}

0 commit comments

Comments
 (0)