Rollup merge of #110176 - nnethercote:renumber-cleanups, r=lqd
Renumbering cleanups r? ``@lqd``
This commit is contained in:
commit
827b74c709
@ -20,31 +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);
|
||||
}
|
||||
|
||||
/// 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<TyCtxt<'tcx>>,
|
||||
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())
|
||||
})
|
||||
renumberer.visit_body(body);
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
@ -82,21 +64,26 @@ 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<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
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())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@ -124,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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user