Skip to content

Commit

Permalink
const_prop: only call error_to_const_error if we are actually showing…
Browse files Browse the repository at this point in the history
… something
  • Loading branch information
RalfJung committed Aug 27, 2019
1 parent 53df91a commit 7677d1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand All @@ -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",
Expand Down

0 comments on commit 7677d1f

Please sign in to comment.