From 33527755a33674880093199e311f1d578edd7397 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 11 Apr 2023 13:25:32 +1000 Subject: [PATCH 1/3] Inline and remove `renumber_regions`. It has a single callsite. --- compiler/rustc_borrowck/src/renumber.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 0fbf01dbe4455..6913d74af9432 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -29,24 +29,6 @@ pub fn renumber_mir<'tcx>( visitor.visit_body(body); } -/// Replaces all regions appearing in `value` with fresh inference -/// variables. -#[instrument(skip(infcx, get_ctxt_fn), level = "debug")] -pub(crate) fn renumber_regions<'tcx, T, F>( - infcx: &BorrowckInferCtxt<'_, 'tcx>, - value: T, - get_ctxt_fn: F, -) -> T -where - T: TypeFoldable>, - F: Fn() -> RegionCtxt, -{ - infcx.tcx.fold_regions(value, |_region, _depth| { - let origin = NllRegionVariableOrigin::Existential { from_forall: false }; - infcx.next_nll_region_var(origin, || get_ctxt_fn()) - }) -} - #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub(crate) enum BoundRegionInfo { Name(Symbol), @@ -87,12 +69,17 @@ struct NllVisitor<'a, 'tcx> { } impl<'a, 'tcx> NllVisitor<'a, 'tcx> { + /// Replaces all regions appearing in `value` with fresh inference + /// variables. fn renumber_regions(&mut self, value: T, region_ctxt_fn: F) -> T where T: TypeFoldable>, F: Fn() -> RegionCtxt, { - renumber_regions(self.infcx, value, region_ctxt_fn) + let origin = NllRegionVariableOrigin::Existential { from_forall: false }; + self.infcx.tcx.fold_regions(value, |_region, _depth| { + self.infcx.next_nll_region_var(origin, || region_ctxt_fn()) + }) } } From 7e8905cd18901fb0a2fdc68bfbf3133291ca2183 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 11 Apr 2023 13:25:57 +1000 Subject: [PATCH 2/3] Rename a variable. --- compiler/rustc_borrowck/src/renumber.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 6913d74af9432..07962267594ce 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -111,9 +111,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> { } #[instrument(skip(self), level = "debug")] - fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) { + fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) { let literal = constant.literal; - constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location)); + constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location)); debug!("constant: {:#?}", constant); } } From 74463214a619a7e9d2d0dc5c6e299c0d0f6f14a5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 12 Apr 2023 07:44:37 +1000 Subject: [PATCH 3/3] Rename `NllVisitor` as `RegionRenumberer`. It's a more descriptive name. --- compiler/rustc_borrowck/src/renumber.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 07962267594ce..2c1d74ef9ca85 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -20,13 +20,13 @@ pub fn renumber_mir<'tcx>( ) { debug!(?body.arg_count); - let mut visitor = NllVisitor { infcx }; + let mut renumberer = RegionRenumberer { infcx }; for body in promoted.iter_mut() { - visitor.visit_body(body); + renumberer.visit_body(body); } - visitor.visit_body(body); + renumberer.visit_body(body); } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] @@ -64,11 +64,11 @@ impl RegionCtxt { } } -struct NllVisitor<'a, 'tcx> { +struct RegionRenumberer<'a, 'tcx> { infcx: &'a BorrowckInferCtxt<'a, 'tcx>, } -impl<'a, 'tcx> NllVisitor<'a, 'tcx> { +impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> { /// Replaces all regions appearing in `value` with fresh inference /// variables. fn renumber_regions(&mut self, value: T, region_ctxt_fn: F) -> T @@ -83,7 +83,7 @@ impl<'a, 'tcx> NllVisitor<'a, 'tcx> { } } -impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> { +impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx }