Skip to content

Commit d6a98db

Browse files
committed
factor out lookup_bound_region
1 parent 09f4172 commit d6a98db

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,31 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> {
194194
scope
195195
}
196196

197+
fn lookup_bound_region(
198+
&self,
199+
debruijn: ty::DebruijnIndex,
200+
br: &ty::BoundRegion,
201+
scopes: &[BoundRegionScope],
202+
) -> RegionVid {
203+
// The debruijn index is a "reverse index" into the
204+
// scopes listing. So when we have INNERMOST (0), we
205+
// want the *last* scope pushed, and so forth.
206+
let debruijn_index = debruijn.index() - ty::INNERMOST.index();
207+
let scope = &scopes[scopes.len() - debruijn_index - 1];
208+
209+
// Find this bound region in that scope to map to a
210+
// particular region.
211+
scope.map[br]
212+
}
213+
197214
fn replace_bound_region(
198215
&self,
199216
universal_regions: &UniversalRegions<'tcx>,
200217
r: ty::Region<'tcx>,
201218
scopes: &[BoundRegionScope],
202219
) -> RegionVid {
203220
match r {
204-
ty::ReLateBound(debruijn, br) => {
205-
// The debruijn index is a "reverse index" into the
206-
// scopes listing. So when we have INNERMOST (0), we
207-
// want the *last* scope pushed, and so forth.
208-
let debruijn_index = debruijn.index() - ty::INNERMOST.index();
209-
let scope = &scopes[scopes.len() - debruijn_index - 1];
210-
211-
// Find this bound region in that scope to map to a
212-
// particular region.
213-
scope.map[br]
214-
}
221+
ty::ReLateBound(debruijn, br) => self.lookup_bound_region(*debruijn, br, scopes),
215222

216223
ty::ReVar(v) => *v,
217224

0 commit comments

Comments
 (0)