Skip to content

Commit 6e6fe30

Browse files
Comment why normalization is needed for debug assertions
1 parent dd51b36 commit 6e6fe30

File tree

2 files changed

+14
-2
lines changed
  • compiler

2 files changed

+14
-2
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
554554
val: &mir::ConstantKind<'tcx>,
555555
layout: Option<TyAndLayout<'tcx>>,
556556
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
557+
// FIXME(const_prop): normalization needed b/c const prop lint in
558+
// `mir_drops_elaborated_and_const_checked`, which happens before
559+
// optimized MIR. Only after optimizing the MIR can we guarantee
560+
// that the `RevealAll` pass has happened and that the body's consts
561+
// are normalized, so any call to resolve before that needs to be
562+
// manually normalized.
563+
let val = self.tcx.normalize_erasing_regions(self.param_env, *val);
557564
match val {
558565
mir::ConstantKind::Ty(ct) => {
559566
match ct.kind() {
@@ -585,7 +592,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
585592
}
586593
}
587594
}
588-
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout),
595+
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(val, ty, layout),
589596
mir::ConstantKind::Unevaluated(uv, _) => {
590597
let instance = self.resolve(uv.def, uv.substs)?;
591598
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
483483
// Use `Reveal::All` here because patterns are always monomorphic even if their function
484484
// isn't.
485485
let param_env_reveal_all = self.param_env.with_reveal_all_normalized(self.tcx);
486-
let substs = self.typeck_results.node_substs(id);
486+
// N.B. There is no guarantee that substs collected in typeck results are fully normalized,
487+
// so they need to be normalized in order to pass to `Instance::resolve`, which will ICE
488+
// if given unnormalized types.
489+
let substs = self
490+
.tcx
491+
.normalize_erasing_regions(param_env_reveal_all, self.typeck_results.node_substs(id));
487492
let instance = match ty::Instance::resolve(self.tcx, param_env_reveal_all, def_id, substs) {
488493
Ok(Some(i)) => i,
489494
Ok(None) => {

0 commit comments

Comments
 (0)