about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-02-09 16:51:36 +0100
committerRalf Jung <post@ralfj.de>2020-02-13 10:56:38 +0100
commitf3ff02bdd85255ad75bae40aad53e520e37a8e4a (patch)
treefb244e42a7fcbf5ee2644cd0c9d24d008c6e36ae
parentc5709ff6b779d88c0d432f6ed8731fde6e55c090 (diff)
downloadrust-f3ff02bdd85255ad75bae40aad53e520e37a8e4a.tar.gz
rust-f3ff02bdd85255ad75bae40aad53e520e37a8e4a.zip
remove PanicInfo::Panic variant that MIR does not use or need
-rw-r--r--src/librustc/mir/interpret/error.rs9
-rw-r--r--src/librustc/mir/mod.rs6
-rw-r--r--src/librustc/mir/visit.rs2
-rw-r--r--src/librustc_mir/const_eval/error.rs10
-rw-r--r--src/librustc_mir/const_eval/machine.rs7
5 files changed, 16 insertions, 18 deletions
diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs
index e819dfbacd8..da8c0bf266f 100644
--- a/src/librustc/mir/interpret/error.rs
+++ b/src/librustc/mir/interpret/error.rs
@@ -11,7 +11,6 @@ use hir::GeneratorKind;
 use rustc_errors::{struct_span_err, DiagnosticBuilder};
 use rustc_hir as hir;
 use rustc_macros::HashStable;
-use rustc_span::symbol::Symbol;
 use rustc_span::{Pos, Span};
 use rustc_target::spec::abi::Abi;
 use std::{any::Any, env, fmt};
@@ -272,7 +271,6 @@ impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
 /// FIXME: this is not actually an InterpError, and should probably be moved to another module.
 #[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
 pub enum PanicInfo<O> {
-    Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
     BoundsCheck { len: O, index: O },
     Overflow(mir::BinOp),
     OverflowNeg,
@@ -288,7 +286,7 @@ pub type AssertMessage<'tcx> = PanicInfo<mir::Operand<'tcx>>;
 impl<O> PanicInfo<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.
+    /// The caller is expected to handle `BoundsCheck` separately.
     pub fn description(&self) -> &'static str {
         use PanicInfo::*;
         match self {
@@ -307,7 +305,7 @@ impl<O> PanicInfo<O> {
             ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion",
             ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking",
             ResumedAfterPanic(GeneratorKind::Async(_)) => "`async fn` resumed after panicking",
-            Panic { .. } | BoundsCheck { .. } => bug!("Unexpected PanicInfo"),
+            BoundsCheck { .. } => bug!("Unexpected PanicInfo"),
         }
     }
 }
@@ -316,9 +314,6 @@ impl<O: fmt::Debug> fmt::Debug for PanicInfo<O> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         use PanicInfo::*;
         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)
             }
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index f6c7174649f..05011241557 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -2671,8 +2671,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
                     BoundsCheck { ref len, ref index } => {
                         BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
                     }
-                    Panic { .. }
-                    | Overflow(_)
+                    Overflow(_)
                     | OverflowNeg
                     | DivisionByZero
                     | RemainderByZero
@@ -2721,8 +2720,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
                         BoundsCheck { ref len, ref index } => {
                             len.visit_with(visitor) || index.visit_with(visitor)
                         }
-                        Panic { .. }
-                        | Overflow(_)
+                        Overflow(_)
                         | OverflowNeg
                         | DivisionByZero
                         | RemainderByZero
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs
index 2f094516a35..555beaa8ca7 100644
--- a/src/librustc/mir/visit.rs
+++ b/src/librustc/mir/visit.rs
@@ -539,7 +539,7 @@ macro_rules! make_mir_visitor {
                         self.visit_operand(len, location);
                         self.visit_operand(index, location);
                     }
-                    Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
+                    Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
                     ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
                         // Nothing to visit
                     }
diff --git a/src/librustc_mir/const_eval/error.rs b/src/librustc_mir/const_eval/error.rs
index e0e78546099..edf0f0a7dbe 100644
--- a/src/librustc_mir/const_eval/error.rs
+++ b/src/librustc_mir/const_eval/error.rs
@@ -1,6 +1,8 @@
 use std::error::Error;
 use std::fmt;
 
+use rustc_span::Symbol;
+
 use super::InterpCx;
 use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, PanicInfo};
 
@@ -9,7 +11,8 @@ use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, Pani
 pub enum ConstEvalErrKind {
     NeedsRfc(String),
     ConstAccessesStatic,
-    Panic(PanicInfo<u64>),
+    AssertFailure(PanicInfo<u64>),
+    Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
 }
 
 // The errors become `MachineStop` with plain strings when being raised.
@@ -29,7 +32,10 @@ impl fmt::Display for ConstEvalErrKind {
                 write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
             }
             ConstAccessesStatic => write!(f, "constant accesses static"),
-            Panic(ref msg) => write!(f, "{:?}", msg),
+            AssertFailure(ref msg) => write!(f, "{:?}", msg),
+            Panic { msg, line, col, file } => {
+                write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col)
+            }
         }
     }
 }
diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs
index 688eee05dda..e0f146c6dc0 100644
--- a/src/librustc_mir/const_eval/machine.rs
+++ b/src/librustc_mir/const_eval/machine.rs
@@ -13,7 +13,7 @@ use rustc_span::symbol::Symbol;
 
 use crate::interpret::{
     self, snapshot, AllocId, Allocation, AssertMessage, GlobalId, ImmTy, InterpCx, InterpResult,
-    Memory, MemoryKind, OpTy, PanicInfo, PlaceTy, Pointer, Scalar,
+    Memory, MemoryKind, OpTy, PlaceTy, Pointer, Scalar,
 };
 
 use super::error::*;
@@ -78,7 +78,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
             let msg = Symbol::intern(self.read_str(msg_place)?);
             let span = self.find_closest_untracked_caller_location().unwrap_or(span);
             let (file, line, col) = self.location_triple_for_span(span);
-            Err(ConstEvalErrKind::Panic(PanicInfo::Panic { msg, file, line, col }).into())
+            Err(ConstEvalErrKind::Panic { msg, file, line, col }.into())
         } else {
             Ok(false)
         }
@@ -304,9 +304,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
             RemainderByZero => RemainderByZero,
             ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind),
             ResumedAfterPanic(generator_kind) => ResumedAfterPanic(*generator_kind),
-            Panic { .. } => bug!("`Panic` variant cannot occur in MIR"),
         };
-        Err(ConstEvalErrKind::Panic(err).into())
+        Err(ConstEvalErrKind::AssertFailure(err).into())
     }
 
     fn ptr_to_int(_mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx, u64> {