Skip to content

Commit 99d271f

Browse files
authored
Rollup merge of rust-lang#63958 - RalfJung:silence-const-prop, r=oli-obk
const_prop: only call error_to_const_error if we are actually showing something This makes `RUSTC_CTFE_BACKTRACE` useful again. r? @oli-obk Fixes rust-lang#63439
2 parents 52c3846 + 7677d1f commit 99d271f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ pub fn const_variant_index<'tcx>(
519519
ecx.read_discriminant(op).unwrap().1
520520
}
521521

522+
/// Turn an interpreter error into something to report to the user.
523+
/// As a side-effect, if RUSTC_CTFE_BACKTRACE is set, this prints the backtrace.
524+
/// Should be called only if the error is actually going to to be reported!
522525
pub fn error_to_const_error<'mir, 'tcx>(
523526
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
524527
mut error: InterpErrorInfo<'tcx>,

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
237237
let r = match f(self) {
238238
Ok(val) => Some(val),
239239
Err(error) => {
240-
let diagnostic = error_to_const_error(&self.ecx, error);
241240
use rustc::mir::interpret::InterpError::*;
242-
match diagnostic.error {
241+
match error.kind {
243242
Exit(_) => bug!("the CTFE program cannot exit"),
244243
Unsupported(_)
245244
| UndefinedBehavior(_)
@@ -248,6 +247,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
248247
// Ignore these errors.
249248
}
250249
Panic(_) => {
250+
let diagnostic = error_to_const_error(&self.ecx, error);
251251
diagnostic.report_as_lint(
252252
self.ecx.tcx,
253253
"this expression will panic at runtime",

0 commit comments

Comments
 (0)