summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_borrowck/src/renumber.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_borrowck/src/renumber.rs')
-rw-r--r--compiler/rustc_borrowck/src/renumber.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs
index 7a8ce621c..63b2088f7 100644
--- a/compiler/rustc_borrowck/src/renumber.rs
+++ b/compiler/rustc_borrowck/src/renumber.rs
@@ -2,6 +2,7 @@ use rustc_index::vec::IndexVec;
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
use rustc_middle::mir::visit::{MutVisitor, TyContext};
use rustc_middle::mir::{Body, Location, Promoted};
+use rustc_middle::mir::{Constant, ConstantKind};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
@@ -37,6 +38,21 @@ where
})
}
+// FIXME(valtrees): This function is necessary because `fold_regions`
+// panics for mir constants in the visitor.
+//
+// Once `visit_mir_constant` is removed we can also remove this function
+// and just use `renumber_regions`.
+fn renumber_regions_in_mir_constant<'tcx>(
+ infcx: &InferCtxt<'_, 'tcx>,
+ value: ConstantKind<'tcx>,
+) -> ConstantKind<'tcx> {
+ infcx.tcx.super_fold_regions(value, |_region, _depth| {
+ let origin = NllRegionVariableOrigin::Existential { from_forall: false };
+ infcx.next_nll_region_var(origin)
+ })
+}
+
struct NllVisitor<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
}
@@ -48,6 +64,13 @@ impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
{
renumber_regions(self.infcx, value)
}
+
+ fn renumber_regions_in_mir_constant(
+ &mut self,
+ value: ConstantKind<'tcx>,
+ ) -> ConstantKind<'tcx> {
+ renumber_regions_in_mir_constant(self.infcx, value)
+ }
}
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
@@ -77,7 +100,10 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
debug!(?region);
}
- fn visit_const(&mut self, constant: &mut ty::Const<'tcx>, _location: Location) {
- *constant = self.renumber_regions(*constant);
+ #[instrument(skip(self), level = "debug")]
+ fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
+ let literal = constant.literal;
+ constant.literal = self.renumber_regions_in_mir_constant(literal);
+ debug!("constant: {:#?}", constant);
}
}