]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/mir/interpret/error.rs
moving some variants from InterpError to EvalErrorPanic
[rust.git] / src / librustc / mir / interpret / error.rs
index c8f42b1c604a587b2315e135ae6b51b6eb0d0676..41ec2029c816ea8c4d46a2b233dd86c77ebd4d5c 100644 (file)
@@ -228,6 +228,24 @@ fn from(kind: InterpError<'tcx, u64>) -> Self {
 
 pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>;
 
+#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
+pub enum EvalErrorPanic<O> {
+    Panic {
+        msg: Symbol,
+        line: u32,
+        col: u32,
+        file: Symbol,
+    },
+    BoundsCheck {
+        len: O,
+        index: O,
+    },
+    Overflow(mir::BinOp),
+    OverflowNeg,
+    DivisionByZero,
+    RemainderByZero,
+}
+
 #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
 pub enum InterpError<'tcx, O> {
     /// This variant is used by machines to signal their own errors that do not
@@ -266,11 +284,6 @@ pub enum InterpError<'tcx, O> {
     Unimplemented(String),
     DerefFunctionPointer,
     ExecuteMemory,
-    BoundsCheck { len: O, index: O },
-    Overflow(mir::BinOp),
-    OverflowNeg,
-    DivisionByZero,
-    RemainderByZero,
     Intrinsic(String),
     InvalidChar(u128),
     StackFrameLimitReached,
@@ -298,12 +311,7 @@ pub enum InterpError<'tcx, O> {
     HeapAllocZeroBytes,
     HeapAllocNonPowerOfTwoAlignment(u64),
     Unreachable,
-    Panic {
-        msg: Symbol,
-        line: u32,
-        col: u32,
-        file: Symbol,
-    },
+    Panic(EvalErrorPanic<O>),
     ReadFromReturnPointer,
     PathNotFound(Vec<String>),
     UnimplementedTraitSelection,
@@ -369,8 +377,6 @@ pub fn description(&self) -> &str {
                 "tried to dereference a function pointer",
             ExecuteMemory =>
                 "tried to treat a memory pointer as a function pointer",
-            BoundsCheck{..} =>
-                "array index out of bounds",
             Intrinsic(..) =>
                 "intrinsic failed",
             NoMirFor(..) =>
@@ -422,8 +428,32 @@ pub fn description(&self) -> &str {
                 two",
             Unreachable =>
                 "entered unreachable code",
-            Panic { .. } =>
+            Panic(EvalErrorPanic::Panic{..}) =>
                 "the evaluated program panicked",
+            Panic(EvalErrorPanic::BoundsCheck{..}) =>
+                "array index out of bounds",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Add)) =>
+                "attempt to add with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Sub)) =>
+                "attempt to subtract with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Mul)) =>
+                "attempt to multiply with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Div)) =>
+                "attempt to divide with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Rem)) =>
+                "attempt to calculate the remainder with overflow",
+            Panic(EvalErrorPanic::OverflowNeg) =>
+                "attempt to negate with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Shr)) =>
+                "attempt to shift right with overflow",
+            Panic(EvalErrorPanic::Overflow(mir::BinOp::Shl)) =>
+                "attempt to shift left with overflow",
+            Panic(EvalErrorPanic::Overflow(op)) =>
+                bug!("{:?} cannot overflow", op),
+            Panic(EvalErrorPanic::DivisionByZero) =>
+                "attempt to divide by zero",
+            Panic(EvalErrorPanic::RemainderByZero) =>
+                "attempt to calculate the remainder with a divisor of zero",
             ReadFromReturnPointer =>
                 "tried to read from the return pointer",
             PathNotFound(_) =>
@@ -436,17 +466,6 @@ pub fn description(&self) -> &str {
                 "encountered overly generic constant",
             ReferencedConstant =>
                 "referenced constant has errors",
-            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",
             InfiniteLoop =>
@@ -493,8 +512,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                     callee_ty, caller_ty),
             FunctionArgCountMismatch =>
                 write!(f, "tried to call a function with incorrect number of arguments"),
-            BoundsCheck { ref len, ref index } =>
-                write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index),
             ReallocatedWrongMemoryKind(ref old, ref new) =>
                 write!(f, "tried to reallocate memory from {} to {}", old, new),
             DeallocatedWrongMemoryKind(ref old, ref new) =>
@@ -518,8 +535,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 write!(f, "incorrect alloc info: expected size {} and align {}, \
                            got size {} and align {}",
                     size.bytes(), align.bytes(), size2.bytes(), align2.bytes()),
-            Panic { ref msg, line, col, ref file } =>
+            Panic(EvalErrorPanic::Panic { ref msg, line, col, ref file }) =>
                 write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col),
+            Panic(EvalErrorPanic::BoundsCheck { ref len, ref index }) =>
+                write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index),
             InvalidDiscriminant(val) =>
                 write!(f, "encountered invalid enum discriminant {}", val),
             Exit(code) =>