From 2f2c90e733a703f69cf13ae79ec623901d42ba2c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 25 Jan 2018 14:15:56 +0100 Subject: [PATCH] Destructure Rc wrapped ErrorKind in miri --- src/librustc_mir/interpret/const_eval.rs | 14 ++++++++------ src/librustc_mir/interpret/eval_context.rs | 11 ++++++----- src/librustc_mir/transform/instcombine.rs | 6 +----- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/librustc_mir/interpret/const_eval.rs b/src/librustc_mir/interpret/const_eval.rs index c2bb9f2efe1..611633163fa 100644 --- a/src/librustc_mir/interpret/const_eval.rs +++ b/src/librustc_mir/interpret/const_eval.rs @@ -235,13 +235,15 @@ impl<'mir, 'tcx> super::Machine<'mir, 'tcx> for CompileTimeEvaluator { } let mir = match ecx.load_mir(instance.def) { Ok(mir) => mir, - Err(EvalError { kind: EvalErrorKind::NoMirFor(path), .. }) => { - return Err( - ConstEvalError::NeedsRfc(format!("calling extern function `{}`", path)) - .into(), - ); + Err(err) => { + if let EvalErrorKind::NoMirFor(ref path) = *err.kind { + return Err( + ConstEvalError::NeedsRfc(format!("calling extern function `{}`", path)) + .into(), + ); + } + return Err(err); } - Err(other) => return Err(other), }; let (return_place, return_to_block) = match destination { Some((place, block)) => (place, StackPopCleanup::Goto(block)), diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index e759407f431..eaa1bcb96a9 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -1513,11 +1513,12 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M write!(msg, ":").unwrap(); match self.stack[frame].get_local(local) { - Err(EvalError { kind: EvalErrorKind::DeadLocal, .. }) => { - write!(msg, " is dead").unwrap(); - } Err(err) => { - panic!("Failed to access local: {:?}", err); + if let EvalErrorKind::DeadLocal = *err.kind { + write!(msg, " is dead").unwrap(); + } else { + panic!("Failed to access local: {:?}", err); + } } Ok(Value::ByRef(ptr, align)) => { match ptr.into_inner_primval() { @@ -1576,7 +1577,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M } pub fn report(&self, e: &mut EvalError, as_err: bool, explicit_span: Option) { - if let EvalErrorKind::TypeckError = e.kind { + if let EvalErrorKind::TypeckError = *e.kind { return; } if let Some(ref mut backtrace) = e.backtrace { diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 25787608e39..640fd7cadab 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -362,12 +362,8 @@ impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> { ) } else { if overflow { - use rustc::mir::interpret::EvalError; use rustc::mir::interpret::EvalErrorKind; - let mut err = EvalError { - kind: EvalErrorKind::OverflowingMath, - backtrace: None, - }; + let mut err = EvalErrorKind::OverflowingMath.into(); ecx.report(&mut err, false, Some(span)); return None; }