mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
remove PanicInfo::Panic variant that MIR does not use or need
This commit is contained in:
parent
c5709ff6b7
commit
f3ff02bdd8
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user