]> git.lizzy.rs Git - rust.git/commitdiff
use PanicMessage type for MIR assertion errors
authorRalf Jung <post@ralfj.de>
Wed, 24 Jul 2019 08:24:55 +0000 (10:24 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 24 Jul 2019 08:24:55 +0000 (10:24 +0200)
12 files changed:
src/librustc/mir/interpret/error.rs
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc_codegen_ssa/mir/block.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/nll/invalidation.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/build/expr/as_place.rs
src/librustc_mir/build/expr/as_rvalue.rs
src/librustc_mir/interpret/terminator.rs
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/generator.rs

index 4f837241cdd92f97f4eb1e21ad3cf00070b001f3..073ee0028cf43bab59a2c3c56ffe98725362a8c0 100644 (file)
@@ -47,7 +47,7 @@ pub fn assert_reported(self) {
 #[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
 pub struct ConstEvalErr<'tcx> {
     pub span: Span,
-    pub error: crate::mir::interpret::InterpError<'tcx, u64>,
+    pub error: crate::mir::interpret::InterpError<'tcx>,
     pub stacktrace: Vec<FrameInfo<'tcx>>,
 }
 
@@ -185,10 +185,17 @@ pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'
 /// macro for this.
 #[derive(Debug, Clone)]
 pub struct InterpErrorInfo<'tcx> {
-    pub kind: InterpError<'tcx, u64>,
+    pub kind: InterpError<'tcx>,
     backtrace: Option<Box<Backtrace>>,
 }
 
+
+impl<'tcx> fmt::Display for InterpErrorInfo<'tcx> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{}", self.kind)
+    }
+}
+
 impl<'tcx> InterpErrorInfo<'tcx> {
     pub fn print_backtrace(&mut self) {
         if let Some(ref mut backtrace) = self.backtrace {
@@ -202,8 +209,8 @@ fn print_backtrace(backtrace: &mut Backtrace) {
     eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace);
 }
 
-impl<'tcx> From<InterpError<'tcx, u64>> for InterpErrorInfo<'tcx> {
-    fn from(kind: InterpError<'tcx, u64>) -> Self {
+impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
+    fn from(kind: InterpError<'tcx>) -> Self {
         let backtrace = match env::var("RUST_CTFE_BACKTRACE") {
             // Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
             Ok(ref val) if val != "0" => {
@@ -226,8 +233,6 @@ fn from(kind: InterpError<'tcx, u64>) -> Self {
     }
 }
 
-pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>;
-
 #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
 pub enum PanicMessage<O> {
     Panic {
@@ -244,10 +249,68 @@ pub enum PanicMessage<O> {
     OverflowNeg,
     DivisionByZero,
     RemainderByZero,
+    GeneratorResumedAfterReturn,
+    GeneratorResumedAfterPanic,
+}
+
+/// Type for MIR `Assert` terminator error messages.
+pub type AssertMessage<'tcx> = PanicMessage<mir::Operand<'tcx>>;
+
+impl<O> PanicMessage<O> {
+    /// Getting a description does not require `O` to be printable, and does not
+    /// require allocation.
+    /// The caller is expected to handle `Panic` and `BoundsCheck` separately.
+    pub fn description(&self) -> &'static str {
+        use PanicMessage::*;
+        match self {
+            Overflow(mir::BinOp::Add) =>
+                "attempt to add with overflow",
+            Overflow(mir::BinOp::Sub) =>
+                "attempt to subtract with overflow",
+            Overflow(mir::BinOp::Mul) =>
+                "attempt to multiply with overflow",
+            Overflow(mir::BinOp::Div) =>
+                "attempt to divide with overflow",
+            Overflow(mir::BinOp::Rem) =>
+                "attempt to calculate the remainder with overflow",
+            OverflowNeg =>
+                "attempt to negate with overflow",
+            Overflow(mir::BinOp::Shr) =>
+                "attempt to shift right with overflow",
+            Overflow(mir::BinOp::Shl) =>
+                "attempt to shift left with overflow",
+            Overflow(op) =>
+                bug!("{:?} cannot overflow", op),
+            DivisionByZero =>
+                "attempt to divide by zero",
+            RemainderByZero =>
+                "attempt to calculate the remainder with a divisor of zero",
+            GeneratorResumedAfterReturn =>
+                "generator resumed after completion",
+            GeneratorResumedAfterPanic =>
+                "generator resumed after panicking",
+            Panic { .. } | BoundsCheck { .. } =>
+                bug!("Unexpected PanicMessage"),
+        }
+    }
+}
+
+impl<O: fmt::Debug> fmt::Debug for PanicMessage<O> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        use PanicMessage::*;
+        match self {
+            Panic { ref msg, line, col, ref file } =>
+                write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col),
+            BoundsCheck { ref len, ref index } =>
+                write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index),
+            _ =>
+                write!(f, "{}", self.description()),
+        }
+    }
 }
 
 #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
-pub enum InterpError<'tcx, O> {
+pub enum InterpError<'tcx> {
     /// This variant is used by machines to signal their own errors that do not
     /// match an existing variant.
     MachineError(String),
@@ -311,7 +374,7 @@ pub enum InterpError<'tcx, O> {
     HeapAllocZeroBytes,
     HeapAllocNonPowerOfTwoAlignment(u64),
     Unreachable,
-    Panic(PanicMessage<O>),
+    Panic(PanicMessage<u64>),
     ReadFromReturnPointer,
     PathNotFound(Vec<String>),
     UnimplementedTraitSelection,
@@ -322,28 +385,21 @@ pub enum InterpError<'tcx, O> {
     /// Cannot compute this constant because it depends on another one
     /// which already produced an error
     ReferencedConstant,
-    GeneratorResumedAfterReturn,
-    GeneratorResumedAfterPanic,
     InfiniteLoop,
 }
 
 pub type InterpResult<'tcx, T = ()> = Result<T, InterpErrorInfo<'tcx>>;
 
-impl<'tcx> fmt::Display for InterpErrorInfo<'tcx> {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{}", self.kind)
-    }
-}
-
-impl<'tcx> fmt::Display for InterpError<'tcx, u64> {
+impl<'tcx> fmt::Display for InterpError<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        // Forward `Display` to `Debug`
         write!(f, "{:?}", self)
     }
 }
 
-impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
+impl<'tcx> fmt::Debug for InterpError<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        use self::InterpError::*;
+        use InterpError::*;
         match *self {
             PointerOutOfBounds { ptr, msg, allocation_size } => {
                 write!(f, "{} failed: pointer must be in-bounds at offset {}, \
@@ -457,10 +513,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 write!(f, "encountered overly generic constant"),
             ReferencedConstant =>
                 write!(f, "referenced constant has errors"),
-            GeneratorResumedAfterReturn =>
-                write!(f, "generator resumed after completion"),
-            GeneratorResumedAfterPanic =>
-                write!(f, "generator resumed after panicking"),
             InfiniteLoop =>
                 write!(f, "duplicate interpreter state observed here, const evaluation will never \
                     terminate"),
@@ -479,33 +531,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
             AbiViolation(ref msg) |
             Intrinsic(ref msg) =>
                 write!(f, "{}", msg),
-
-            Panic(PanicMessage::Panic { ref msg, line, col, ref file }) =>
-                write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col),
-            Panic(PanicMessage::BoundsCheck { ref len, ref index }) =>
-                write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index),
-            Panic(PanicMessage::Overflow(mir::BinOp::Add)) =>
-                write!(f, "attempt to add with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Sub)) =>
-                write!(f, "attempt to subtract with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Mul)) =>
-                write!(f, "attempt to multiply with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Div)) =>
-                write!(f, "attempt to divide with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Rem)) =>
-                write!(f, "attempt to calculate the remainder with overflow"),
-            Panic(PanicMessage::OverflowNeg) =>
-                write!(f, "attempt to negate with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Shr)) =>
-                write!(f, "attempt to shift right with overflow"),
-            Panic(PanicMessage::Overflow(mir::BinOp::Shl)) =>
-                write!(f, "attempt to shift left with overflow"),
-            Panic(PanicMessage::Overflow(op)) =>
-                bug!("{:?} cannot overflow", op),
-            Panic(PanicMessage::DivisionByZero) =>
-                write!(f, "attempt to divide by zero"),
-            Panic(PanicMessage::RemainderByZero) =>
-                write!(f, "attempt to calculate the remainder with a divisor of zero"),
+            Panic(ref msg) =>
+                write!(f, "{:?}", msg),
         }
     }
 }
index b1b6be4ae17f8424842d156d8b3c560f6623055d..b3d92e8a604d1e1fff12eae4af3eceae8fe4475e 100644 (file)
@@ -7,7 +7,7 @@
 use crate::hir::def::{CtorKind, Namespace};
 use crate::hir::def_id::DefId;
 use crate::hir::{self, InlineAsm as HirInlineAsm};
-use crate::mir::interpret::{ConstValue, PanicMessage, InterpError::Panic, Scalar};
+use crate::mir::interpret::{ConstValue, PanicMessage, Scalar};
 use crate::mir::visit::MirVisitable;
 use crate::rustc_serialize as serialize;
 use crate::ty::adjustment::PointerCast;
@@ -3152,13 +3152,16 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
                 }
             }
             Assert { ref cond, expected, ref msg, target, cleanup } => {
-                let msg = if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg {
-                    Panic(PanicMessage::BoundsCheck {
-                        len: len.fold_with(folder),
-                        index: index.fold_with(folder),
-                    })
-                } else {
-                    msg.clone()
+                use PanicMessage::*;
+                let msg = match msg {
+                    BoundsCheck { ref len, ref index } =>
+                        BoundsCheck {
+                            len: len.fold_with(folder),
+                            index: index.fold_with(folder),
+                        },
+                    Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
+                    GeneratorResumedAfterReturn | GeneratorResumedAfterPanic =>
+                        msg.clone(),
                 };
                 Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
             }
@@ -3197,10 +3200,14 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
             }
             Assert { ref cond, ref msg, .. } => {
                 if cond.visit_with(visitor) {
-                    if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg {
-                        len.visit_with(visitor) || index.visit_with(visitor)
-                    } else {
-                        false
+                    use PanicMessage::*;
+                    match msg {
+                        BoundsCheck { ref len, ref index } =>
+                            len.visit_with(visitor) || index.visit_with(visitor),
+                        Panic { .. } | Overflow(_) | OverflowNeg |
+                        DivisionByZero | RemainderByZero |
+                        GeneratorResumedAfterReturn | GeneratorResumedAfterPanic =>
+                            false
                     }
                 } else {
                     false
index dca56cc526ce5b51401b1f1562e77232a7039515..7562981f94f61aab897ad68a74b17c7b37c09669 100644 (file)
@@ -514,11 +514,16 @@ fn super_terminator_kind(&mut self,
             fn super_assert_message(&mut self,
                                     msg: & $($mutability)? AssertMessage<'tcx>,
                                     location: Location) {
-                use crate::mir::interpret::InterpError::*;
-                use crate::mir::interpret::PanicMessage::BoundsCheck;
-                if let Panic(BoundsCheck { len, index }) = msg {
-                    self.visit_operand(len, location);
-                    self.visit_operand(index, location);
+                use crate::mir::interpret::PanicMessage::*;
+                match msg {
+                    BoundsCheck { len, index } => {
+                        self.visit_operand(len, location);
+                        self.visit_operand(index, location);
+                    }
+                    Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
+                    GeneratorResumedAfterReturn | GeneratorResumedAfterPanic => {
+                        // Nothing to visit
+                    }
                 }
             }
 
index 27eddca8542d0ef7e43fe4fbe934eb6155913715..984ff80f03e963d10f66c08b030c2c9b408b5ad3 100644 (file)
@@ -368,7 +368,7 @@ fn codegen_assert_terminator<'b>(
         // checked operation, just a comparison with the minimum
         // value, so we have to check for the assert message.
         if !bx.check_overflow() {
-            if let InterpError::Panic(PanicMessage::OverflowNeg) = *msg {
+            if let PanicMessage::OverflowNeg = *msg {
                 const_cond = Some(expected);
             }
         }
@@ -402,8 +402,8 @@ fn codegen_assert_terminator<'b>(
         let col = bx.const_u32(loc.col.to_usize() as u32 + 1);
 
         // Put together the arguments to the panic entry point.
-        let (lang_item, args) = match *msg {
-            InterpError::Panic(PanicMessage::BoundsCheck { ref len, ref index }) => {
+        let (lang_item, args) = match msg {
+            PanicMessage::BoundsCheck { ref len, ref index } => {
                 let len = self.codegen_operand(&mut bx, len).immediate();
                 let index = self.codegen_operand(&mut bx, index).immediate();
 
@@ -418,8 +418,8 @@ fn codegen_assert_terminator<'b>(
                     vec![file_line_col, index, len])
             }
             _ => {
-                let str = format!("{:?}", msg);
-                let msg_str = LocalInternedString::intern(&str);
+                let str = msg.description();
+                let msg_str = LocalInternedString::intern(str);
                 let msg_file_line_col = bx.static_panic_msg(
                     Some(msg_str),
                     filename,
index 8d27a32a285d8499e544273623c5a50c1f68565a..92285c47db481460ee183db79922bf349cc85e2a 100644 (file)
@@ -733,8 +733,8 @@ fn visit_terminator_entry(
                 cleanup: _,
             } => {
                 self.consume_operand(loc, (cond, span), flow_state);
-                use rustc::mir::interpret::{InterpError::Panic, PanicMessage};
-                if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg {
+                use rustc::mir::interpret::PanicMessage;
+                if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
                     self.consume_operand(loc, (len, span), flow_state);
                     self.consume_operand(loc, (index, span), flow_state);
                 }
index 90df0c91c7235b43ee33d46701274214c14001f2..aa9e68bd7de4412bf91e7e5cb0b2a291bbf40f35 100644 (file)
@@ -207,8 +207,8 @@ fn visit_terminator_kind(
                 cleanup: _,
             } => {
                 self.consume_operand(location, cond);
-                use rustc::mir::interpret::{InterpError::Panic, PanicMessage::BoundsCheck};
-                if let Panic(BoundsCheck { ref len, ref index }) = *msg {
+                use rustc::mir::interpret::PanicMessage;
+                if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
                     self.consume_operand(location, len);
                     self.consume_operand(location, index);
                 }
index 6ce2f968ed72d0f9c469bcec382a4a0fabc2cb91..59a8c8d34d2a1cf26a81e44e793040015b8114a3 100644 (file)
@@ -28,7 +28,7 @@
 use rustc::infer::outlives::env::RegionBoundPairs;
 use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
 use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc::mir::interpret::{InterpError::Panic, ConstValue, PanicMessage};
+use rustc::mir::interpret::{ConstValue, PanicMessage};
 use rustc::mir::tcx::PlaceTy;
 use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext};
 use rustc::mir::*;
@@ -1606,7 +1606,7 @@ fn check_terminator(
                     span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
                 }
 
-                if let Panic(PanicMessage::BoundsCheck { ref len, ref index }) = *msg {
+                if let PanicMessage::BoundsCheck { ref len, ref index } = *msg {
                     if len.ty(body, tcx) != tcx.types.usize {
                         span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
                     }
index 42d08a728e0a749805f305a86f3425e1c10de1b1..7a428a2ec9f3626d149714db264af8bf077c7e0b 100644 (file)
@@ -4,7 +4,7 @@
 use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
 use crate::build::{BlockAnd, BlockAndExtension, Builder};
 use crate::hair::*;
-use rustc::mir::interpret::{InterpError::Panic, PanicMessage::BoundsCheck};
+use rustc::mir::interpret::{PanicMessage::BoundsCheck};
 use rustc::mir::*;
 use rustc::ty::{CanonicalUserTypeAnnotation, Variance};
 
@@ -105,10 +105,10 @@ fn expr_as_place(
                     ),
                 );
 
-                let msg = Panic(BoundsCheck {
+                let msg = BoundsCheck {
                     len: Operand::Move(len),
                     index: Operand::Copy(Place::from(idx)),
-                });
+                };
                 let success = this.assert(block, Operand::Move(lt), true, msg, expr_span);
                 success.and(slice.index(idx))
             }
index 8790ebc41693faa9d5ba93256150c401ae98655c..92daf06e6f8fefea4dbf21dba879996b2d431c74 100644 (file)
@@ -7,7 +7,7 @@
 use crate::build::{BlockAnd, BlockAndExtension, Builder};
 use crate::hair::*;
 use rustc::middle::region;
-use rustc::mir::interpret::{InterpError::Panic, PanicMessage};
+use rustc::mir::interpret::PanicMessage;
 use rustc::mir::*;
 use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
 use syntax_pos::Span;
@@ -101,7 +101,7 @@ fn expr_as_rvalue(
                         block,
                         Operand::Move(is_min),
                         false,
-                        Panic(PanicMessage::OverflowNeg),
+                        PanicMessage::OverflowNeg,
                         expr_span,
                     );
                 }
@@ -401,7 +401,7 @@ pub fn build_binary_op(
             let val = result_value.clone().field(val_fld, ty);
             let of = result_value.field(of_fld, bool_ty);
 
-            let err = Panic(PanicMessage::Overflow(op));
+            let err = PanicMessage::Overflow(op);
 
             block = self.assert(block, Operand::Move(of), false, err, span);
 
@@ -411,11 +411,12 @@ pub fn build_binary_op(
                 // Checking division and remainder is more complex, since we 1. always check
                 // and 2. there are two possible failure cases, divide-by-zero and overflow.
 
-                let (zero_err, overflow_err) = if op == BinOp::Div {
-                    (Panic(PanicMessage::DivisionByZero), Panic(PanicMessage::Overflow(op)))
+                let zero_err = if op == BinOp::Div {
+                    PanicMessage::DivisionByZero
                 } else {
-                    (Panic(PanicMessage::RemainderByZero), Panic(PanicMessage::Overflow(op)))
+                    PanicMessage::RemainderByZero
                 };
+                let overflow_err = PanicMessage::Overflow(op);
 
                 // Check for / 0
                 let is_zero = self.temp(bool_ty, span);
index a85b77c7b8143e397250cca72a2057252d36b6f1..27bd0f88896340d1a8df827de43555e1334f5c3c 100644 (file)
@@ -7,7 +7,7 @@
 use rustc_target::spec::abi::Abi;
 
 use super::{
-    InterpResult, PointerArithmetic, InterpError, Scalar, PanicMessage,
+    InterpResult, PointerArithmetic, InterpError, Scalar,
     InterpCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup, FnVal,
 };
 
@@ -135,28 +135,31 @@ pub(super) fn eval_terminator(
                     self.goto_block(Some(target))?;
                 } else {
                     // Compute error message
-                    use rustc::mir::interpret::InterpError::*;
-                    return match *msg {
-                        Panic(PanicMessage::BoundsCheck { ref len, ref index }) => {
+                    use rustc::mir::interpret::PanicMessage::*;
+                    return match msg {
+                        BoundsCheck { ref len, ref index } => {
                             let len = self.read_immediate(self.eval_operand(len, None)?)
                                 .expect("can't eval len").to_scalar()?
                                 .to_bits(self.memory().pointer_size())? as u64;
                             let index = self.read_immediate(self.eval_operand(index, None)?)
                                 .expect("can't eval index").to_scalar()?
                                 .to_bits(self.memory().pointer_size())? as u64;
-                            err!(Panic(PanicMessage::BoundsCheck { len, index }))
+                            err!(Panic(BoundsCheck { len, index }))
                         }
-                        Panic(PanicMessage::Overflow(op)) =>
-                            Err(Panic(PanicMessage::Overflow(op)).into()),
-                        Panic(PanicMessage::OverflowNeg) =>
-                            Err(Panic(PanicMessage::OverflowNeg).into()),
-                        Panic(PanicMessage::DivisionByZero) =>
-                            Err(Panic(PanicMessage::DivisionByZero).into()),
-                        Panic(PanicMessage::RemainderByZero) =>
-                            Err(Panic(PanicMessage::RemainderByZero).into()),
-                        GeneratorResumedAfterReturn |
-                        GeneratorResumedAfterPanic => unimplemented!(),
-                        _ => bug!(),
+                        Overflow(op) =>
+                            err!(Panic(Overflow(*op))),
+                        OverflowNeg =>
+                            err!(Panic(OverflowNeg)),
+                        DivisionByZero =>
+                            err!(Panic(DivisionByZero)),
+                        RemainderByZero =>
+                            err!(Panic(RemainderByZero)),
+                        GeneratorResumedAfterReturn =>
+                            err!(Panic(GeneratorResumedAfterReturn)),
+                        GeneratorResumedAfterPanic =>
+                            err!(Panic(GeneratorResumedAfterPanic)),
+                        Panic { .. } =>
+                            bug!("`Panic` variant cannot occur in MIR"),
                     };
                 }
             }
index 1d3d20f298d77067380ea85a20f702b1872e1f34..7a2d78b2e986b670626c7c878ef93ddefc402104 100644 (file)
@@ -13,7 +13,7 @@
 use rustc::mir::visit::{
     Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext,
 };
-use rustc::mir::interpret::{InterpError::Panic, Scalar, GlobalId, InterpResult, PanicMessage};
+use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, InterpError, PanicMessage};
 use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
 use syntax_pos::{Span, DUMMY_SP};
 use rustc::ty::subst::InternalSubsts;
@@ -314,8 +314,6 @@ fn use_ecx<F, T>(
                     | HeapAllocNonPowerOfTwoAlignment(_)
                     | Unreachable
                     | ReadFromReturnPointer
-                    | GeneratorResumedAfterReturn
-                    | GeneratorResumedAfterPanic
                     | ReferencedConstant
                     | InfiniteLoop
                     => {
@@ -595,7 +593,7 @@ fn const_prop(
                     )
                 } else {
                     if overflow {
-                        let err = Panic(PanicMessage::Overflow(op)).into();
+                        let err = InterpError::Panic(PanicMessage::Overflow(op)).into();
                         let _: Option<()> = self.use_ecx(source_info, |_| Err(err));
                         return None;
                     }
@@ -831,14 +829,13 @@ fn visit_terminator(
                             .hir()
                             .as_local_hir_id(self.source.def_id())
                             .expect("some part of a failing const eval must be local");
-                        use rustc::mir::interpret::InterpError::*;
                         let msg = match msg {
-                            Panic(PanicMessage::Overflow(_)) |
-                            Panic(PanicMessage::OverflowNeg) |
-                            Panic(PanicMessage::DivisionByZero) |
-                            Panic(PanicMessage::RemainderByZero) =>
-                                format!("{:?}", msg),
-                            Panic(PanicMessage::BoundsCheck { ref len, ref index }) => {
+                            PanicMessage::Overflow(_) |
+                            PanicMessage::OverflowNeg |
+                            PanicMessage::DivisionByZero |
+                            PanicMessage::RemainderByZero =>
+                                msg.description().to_owned(),
+                            PanicMessage::BoundsCheck { ref len, ref index } => {
                                 let len = self
                                     .eval_operand(len, source_info)
                                     .expect("len must be const");
index af412edbdc23f73f32376aa1eba5b7f6369420dd..5461a2e470c7e62a7e2ebb5d4ee23fb5e83586c5 100644 (file)
@@ -1016,7 +1016,7 @@ fn create_generator_resume_function<'tcx>(
 
     let mut cases = create_cases(body, &transform, |point| Some(point.resume));
 
-    use rustc::mir::interpret::InterpError::{
+    use rustc::mir::interpret::PanicMessage::{
         GeneratorResumedAfterPanic,
         GeneratorResumedAfterReturn,
     };