diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-29 05:32:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-29 05:32:50 +0200 |
| commit | 99d271f400b602f79c5f0527bf688ffacf485a7e (patch) | |
| tree | 7da94faf3e877c85bfc01ba01bfc21965e71ce1d | |
| parent | 52c3846d51b8efabebb02bd2587a87905e068290 (diff) | |
| parent | 7677d1f771525606af256e2972cb7116d8fde99f (diff) | |
| download | rust-99d271f400b602f79c5f0527bf688ffacf485a7e.tar.gz rust-99d271f400b602f79c5f0527bf688ffacf485a7e.zip | |
Rollup merge of #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 https://github.com/rust-lang/rust/issues/63439
| -rw-r--r-- | src/librustc_mir/const_eval.rs | 3 | ||||
| -rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 67d63e52b2b..5aa487d9016 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -519,6 +519,9 @@ pub fn const_variant_index<'tcx>( ecx.read_discriminant(op).unwrap().1 } +/// Turn an interpreter error into something to report to the user. +/// As a side-effect, if RUSTC_CTFE_BACKTRACE is set, this prints the backtrace. +/// Should be called only if the error is actually going to to be reported! pub fn error_to_const_error<'mir, 'tcx>( ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>, mut error: InterpErrorInfo<'tcx>, diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index b6146b6b722..f261fdc268b 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -237,9 +237,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let r = match f(self) { Ok(val) => Some(val), Err(error) => { - let diagnostic = error_to_const_error(&self.ecx, error); use rustc::mir::interpret::InterpError::*; - match diagnostic.error { + match error.kind { Exit(_) => bug!("the CTFE program cannot exit"), Unsupported(_) | UndefinedBehavior(_) @@ -248,6 +247,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // Ignore these errors. } Panic(_) => { + let diagnostic = error_to_const_error(&self.ecx, error); diagnostic.report_as_lint( self.ecx.tcx, "this expression will panic at runtime", |
