Skip to content

Commit dfa8f14

Browse files
committed
Do not ICE on invalid consts when walking mono-reachable blocks
1 parent ef8b9dc commit dfa8f14

File tree

1 file changed

+3
-6
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+3
-6
lines changed

compiler/rustc_middle/src/mir/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,7 @@ impl<'tcx> Body<'tcx> {
701701
env,
702702
crate::ty::EarlyBinder::bind(constant.const_),
703703
);
704-
let Some(bits) = mono_literal.try_eval_bits(tcx, env) else {
705-
bug!("Couldn't evaluate constant {:?} in mono {:?}", constant, instance);
706-
};
707-
bits
704+
mono_literal.try_eval_bits(tcx, env)
708705
};
709706

710707
let TerminatorKind::SwitchInt { discr, targets } = &block.terminator().kind else {
@@ -714,7 +711,7 @@ impl<'tcx> Body<'tcx> {
714711
// If this is a SwitchInt(const _), then we can just evaluate the constant and return.
715712
let discr = match discr {
716713
Operand::Constant(constant) => {
717-
let bits = eval_mono_const(constant);
714+
let bits = eval_mono_const(constant)?;
718715
return Some((bits, targets));
719716
}
720717
Operand::Move(place) | Operand::Copy(place) => place,
@@ -748,7 +745,7 @@ impl<'tcx> Body<'tcx> {
748745
match rvalue {
749746
Rvalue::NullaryOp(NullOp::UbChecks, _) => Some((tcx.sess.ub_checks() as u128, targets)),
750747
Rvalue::Use(Operand::Constant(constant)) => {
751-
let bits = eval_mono_const(constant);
748+
let bits = eval_mono_const(constant)?;
752749
Some((bits, targets))
753750
}
754751
_ => None,

0 commit comments

Comments
 (0)