mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +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_errors::{struct_span_err, DiagnosticBuilder};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_span::symbol::Symbol;
|
|
||||||
use rustc_span::{Pos, Span};
|
use rustc_span::{Pos, Span};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use std::{any::Any, env, fmt};
|
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.
|
/// FIXME: this is not actually an InterpError, and should probably be moved to another module.
|
||||||
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
|
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
|
||||||
pub enum PanicInfo<O> {
|
pub enum PanicInfo<O> {
|
||||||
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
|
|
||||||
BoundsCheck { len: O, index: O },
|
BoundsCheck { len: O, index: O },
|
||||||
Overflow(mir::BinOp),
|
Overflow(mir::BinOp),
|
||||||
OverflowNeg,
|
OverflowNeg,
|
||||||
@ -288,7 +286,7 @@ pub type AssertMessage<'tcx> = PanicInfo<mir::Operand<'tcx>>;
|
|||||||
impl<O> PanicInfo<O> {
|
impl<O> PanicInfo<O> {
|
||||||
/// Getting a description does not require `O` to be printable, and does not
|
/// Getting a description does not require `O` to be printable, and does not
|
||||||
/// require allocation.
|
/// 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 {
|
pub fn description(&self) -> &'static str {
|
||||||
use PanicInfo::*;
|
use PanicInfo::*;
|
||||||
match self {
|
match self {
|
||||||
@ -307,7 +305,7 @@ impl<O> PanicInfo<O> {
|
|||||||
ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion",
|
ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion",
|
||||||
ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking",
|
ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking",
|
||||||
ResumedAfterPanic(GeneratorKind::Async(_)) => "`async fn` 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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use PanicInfo::*;
|
use PanicInfo::*;
|
||||||
match self {
|
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 } => {
|
BoundsCheck { ref len, ref index } => {
|
||||||
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, 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 { ref len, ref index } => {
|
||||||
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
|
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
|
||||||
}
|
}
|
||||||
Panic { .. }
|
Overflow(_)
|
||||||
| Overflow(_)
|
|
||||||
| OverflowNeg
|
| OverflowNeg
|
||||||
| DivisionByZero
|
| DivisionByZero
|
||||||
| RemainderByZero
|
| RemainderByZero
|
||||||
@ -2721,8 +2720,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
|||||||
BoundsCheck { ref len, ref index } => {
|
BoundsCheck { ref len, ref index } => {
|
||||||
len.visit_with(visitor) || index.visit_with(visitor)
|
len.visit_with(visitor) || index.visit_with(visitor)
|
||||||
}
|
}
|
||||||
Panic { .. }
|
Overflow(_)
|
||||||
| Overflow(_)
|
|
||||||
| OverflowNeg
|
| OverflowNeg
|
||||||
| DivisionByZero
|
| DivisionByZero
|
||||||
| RemainderByZero
|
| RemainderByZero
|
||||||
|
@ -539,7 +539,7 @@ macro_rules! make_mir_visitor {
|
|||||||
self.visit_operand(len, location);
|
self.visit_operand(len, location);
|
||||||
self.visit_operand(index, location);
|
self.visit_operand(index, location);
|
||||||
}
|
}
|
||||||
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
|
Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
|
||||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
|
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
|
||||||
// Nothing to visit
|
// Nothing to visit
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use rustc_span::Symbol;
|
||||||
|
|
||||||
use super::InterpCx;
|
use super::InterpCx;
|
||||||
use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, PanicInfo};
|
use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, PanicInfo};
|
||||||
|
|
||||||
@ -9,7 +11,8 @@ use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, Pani
|
|||||||
pub enum ConstEvalErrKind {
|
pub enum ConstEvalErrKind {
|
||||||
NeedsRfc(String),
|
NeedsRfc(String),
|
||||||
ConstAccessesStatic,
|
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.
|
// 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)
|
write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
|
||||||
}
|
}
|
||||||
ConstAccessesStatic => write!(f, "constant accesses static"),
|
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::{
|
use crate::interpret::{
|
||||||
self, snapshot, AllocId, Allocation, AssertMessage, GlobalId, ImmTy, InterpCx, InterpResult,
|
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::*;
|
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 msg = Symbol::intern(self.read_str(msg_place)?);
|
||||||
let span = self.find_closest_untracked_caller_location().unwrap_or(span);
|
let span = self.find_closest_untracked_caller_location().unwrap_or(span);
|
||||||
let (file, line, col) = self.location_triple_for_span(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 {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
@ -304,9 +304,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||||||
RemainderByZero => RemainderByZero,
|
RemainderByZero => RemainderByZero,
|
||||||
ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind),
|
ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind),
|
||||||
ResumedAfterPanic(generator_kind) => ResumedAfterPanic(*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> {
|
fn ptr_to_int(_mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx, u64> {
|
||||||
|
Loading…
Reference in New Issue
Block a user