Skip to content

Commit f3ff02b

Browse files
committed
remove PanicInfo::Panic variant that MIR does not use or need
1 parent c5709ff commit f3ff02b

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/librustc/mir/interpret/error.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use hir::GeneratorKind;
1111
use rustc_errors::{struct_span_err, DiagnosticBuilder};
1212
use rustc_hir as hir;
1313
use rustc_macros::HashStable;
14-
use rustc_span::symbol::Symbol;
1514
use rustc_span::{Pos, Span};
1615
use rustc_target::spec::abi::Abi;
1716
use std::{any::Any, env, fmt};
@@ -272,7 +271,6 @@ impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
272271
/// FIXME: this is not actually an InterpError, and should probably be moved to another module.
273272
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
274273
pub enum PanicInfo<O> {
275-
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
276274
BoundsCheck { len: O, index: O },
277275
Overflow(mir::BinOp),
278276
OverflowNeg,
@@ -288,7 +286,7 @@ pub type AssertMessage<'tcx> = PanicInfo<mir::Operand<'tcx>>;
288286
impl<O> PanicInfo<O> {
289287
/// Getting a description does not require `O` to be printable, and does not
290288
/// require allocation.
291-
/// The caller is expected to handle `Panic` and `BoundsCheck` separately.
289+
/// The caller is expected to handle `BoundsCheck` separately.
292290
pub fn description(&self) -> &'static str {
293291
use PanicInfo::*;
294292
match self {
@@ -307,7 +305,7 @@ impl<O> PanicInfo<O> {
307305
ResumedAfterReturn(GeneratorKind::Async(_)) => "`async fn` resumed after completion",
308306
ResumedAfterPanic(GeneratorKind::Gen) => "generator resumed after panicking",
309307
ResumedAfterPanic(GeneratorKind::Async(_)) => "`async fn` resumed after panicking",
310-
Panic { .. } | BoundsCheck { .. } => bug!("Unexpected PanicInfo"),
308+
BoundsCheck { .. } => bug!("Unexpected PanicInfo"),
311309
}
312310
}
313311
}
@@ -316,9 +314,6 @@ impl<O: fmt::Debug> fmt::Debug for PanicInfo<O> {
316314
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317315
use PanicInfo::*;
318316
match self {
319-
Panic { ref msg, line, col, ref file } => {
320-
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col)
321-
}
322317
BoundsCheck { ref len, ref index } => {
323318
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index)
324319
}

src/librustc/mir/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,8 +2671,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
26712671
BoundsCheck { ref len, ref index } => {
26722672
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
26732673
}
2674-
Panic { .. }
2675-
| Overflow(_)
2674+
Overflow(_)
26762675
| OverflowNeg
26772676
| DivisionByZero
26782677
| RemainderByZero
@@ -2721,8 +2720,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
27212720
BoundsCheck { ref len, ref index } => {
27222721
len.visit_with(visitor) || index.visit_with(visitor)
27232722
}
2724-
Panic { .. }
2725-
| Overflow(_)
2723+
Overflow(_)
27262724
| OverflowNeg
27272725
| DivisionByZero
27282726
| RemainderByZero

src/librustc/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ macro_rules! make_mir_visitor {
539539
self.visit_operand(len, location);
540540
self.visit_operand(index, location);
541541
}
542-
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
542+
Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
543543
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
544544
// Nothing to visit
545545
}

src/librustc_mir/const_eval/error.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::error::Error;
22
use std::fmt;
33

4+
use rustc_span::Symbol;
5+
46
use super::InterpCx;
57
use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, PanicInfo};
68

@@ -9,7 +11,8 @@ use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine, Pani
911
pub enum ConstEvalErrKind {
1012
NeedsRfc(String),
1113
ConstAccessesStatic,
12-
Panic(PanicInfo<u64>),
14+
AssertFailure(PanicInfo<u64>),
15+
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
1316
}
1417

1518
// The errors become `MachineStop` with plain strings when being raised.
@@ -29,7 +32,10 @@ impl fmt::Display for ConstEvalErrKind {
2932
write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
3033
}
3134
ConstAccessesStatic => write!(f, "constant accesses static"),
32-
Panic(ref msg) => write!(f, "{:?}", msg),
35+
AssertFailure(ref msg) => write!(f, "{:?}", msg),
36+
Panic { msg, line, col, file } => {
37+
write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col)
38+
}
3339
}
3440
}
3541
}

src/librustc_mir/const_eval/machine.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::symbol::Symbol;
1313

1414
use crate::interpret::{
1515
self, snapshot, AllocId, Allocation, AssertMessage, GlobalId, ImmTy, InterpCx, InterpResult,
16-
Memory, MemoryKind, OpTy, PanicInfo, PlaceTy, Pointer, Scalar,
16+
Memory, MemoryKind, OpTy, PlaceTy, Pointer, Scalar,
1717
};
1818

1919
use super::error::*;
@@ -78,7 +78,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
7878
let msg = Symbol::intern(self.read_str(msg_place)?);
7979
let span = self.find_closest_untracked_caller_location().unwrap_or(span);
8080
let (file, line, col) = self.location_triple_for_span(span);
81-
Err(ConstEvalErrKind::Panic(PanicInfo::Panic { msg, file, line, col }).into())
81+
Err(ConstEvalErrKind::Panic { msg, file, line, col }.into())
8282
} else {
8383
Ok(false)
8484
}
@@ -304,9 +304,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
304304
RemainderByZero => RemainderByZero,
305305
ResumedAfterReturn(generator_kind) => ResumedAfterReturn(*generator_kind),
306306
ResumedAfterPanic(generator_kind) => ResumedAfterPanic(*generator_kind),
307-
Panic { .. } => bug!("`Panic` variant cannot occur in MIR"),
308307
};
309-
Err(ConstEvalErrKind::Panic(err).into())
308+
Err(ConstEvalErrKind::AssertFailure(err).into())
310309
}
311310

312311
fn ptr_to_int(_mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx, u64> {

0 commit comments

Comments
 (0)