Skip to content

Commit 70f73f0

Browse files
Rollup merge of rust-lang#110176 - nnethercote:renumber-cleanups, r=lqd
Renumbering cleanups r? `@lqd`
2 parents 466e5c1 + 7446321 commit 70f73f0

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

compiler/rustc_borrowck/src/renumber.rs

+14-27
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,13 @@ pub fn renumber_mir<'tcx>(
2020
) {
2121
debug!(?body.arg_count);
2222

23-
let mut visitor = NllVisitor { infcx };
23+
let mut renumberer = RegionRenumberer { infcx };
2424

2525
for body in promoted.iter_mut() {
26-
visitor.visit_body(body);
26+
renumberer.visit_body(body);
2727
}
2828

29-
visitor.visit_body(body);
30-
}
31-
32-
/// Replaces all regions appearing in `value` with fresh inference
33-
/// variables.
34-
#[instrument(skip(infcx, get_ctxt_fn), level = "debug")]
35-
pub(crate) fn renumber_regions<'tcx, T, F>(
36-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
37-
value: T,
38-
get_ctxt_fn: F,
39-
) -> T
40-
where
41-
T: TypeFoldable<TyCtxt<'tcx>>,
42-
F: Fn() -> RegionCtxt,
43-
{
44-
infcx.tcx.fold_regions(value, |_region, _depth| {
45-
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
46-
infcx.next_nll_region_var(origin, || get_ctxt_fn())
47-
})
29+
renumberer.visit_body(body);
4830
}
4931

5032
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
@@ -82,21 +64,26 @@ impl RegionCtxt {
8264
}
8365
}
8466

85-
struct NllVisitor<'a, 'tcx> {
67+
struct RegionRenumberer<'a, 'tcx> {
8668
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
8769
}
8870

89-
impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
71+
impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> {
72+
/// Replaces all regions appearing in `value` with fresh inference
73+
/// variables.
9074
fn renumber_regions<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
9175
where
9276
T: TypeFoldable<TyCtxt<'tcx>>,
9377
F: Fn() -> RegionCtxt,
9478
{
95-
renumber_regions(self.infcx, value, region_ctxt_fn)
79+
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
80+
self.infcx.tcx.fold_regions(value, |_region, _depth| {
81+
self.infcx.next_nll_region_var(origin, || region_ctxt_fn())
82+
})
9683
}
9784
}
9885

99-
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
86+
impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
10087
fn tcx(&self) -> TyCtxt<'tcx> {
10188
self.infcx.tcx
10289
}
@@ -124,9 +111,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
124111
}
125112

126113
#[instrument(skip(self), level = "debug")]
127-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
114+
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
128115
let literal = constant.literal;
129-
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location));
116+
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location));
130117
debug!("constant: {:#?}", constant);
131118
}
132119
}

0 commit comments

Comments
 (0)