Skip to content

Commit

Permalink
rename PanicInfo -> AssertKind
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 13, 2020
1 parent 7e7d1c3 commit ed2f22c
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
18 changes: 9 additions & 9 deletions src/librustc/mir/mod.rs
Expand Up @@ -1155,7 +1155,7 @@ pub enum TerminatorKind<'tcx> {

/// Information about an assertion failure.
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
pub enum PanicInfo<O> {
pub enum AssertKind<O> {
BoundsCheck { len: O, index: O },
Overflow(BinOp),
OverflowNeg,
Expand All @@ -1166,7 +1166,7 @@ pub enum PanicInfo<O> {
}

/// Type for MIR `Assert` terminator error messages.
pub type AssertMessage<'tcx> = PanicInfo<Operand<'tcx>>;
pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;

pub type Successors<'a> =
iter::Chain<option::IntoIter<&'a BasicBlock>, slice::Iter<'a, BasicBlock>>;
Expand Down Expand Up @@ -1397,12 +1397,12 @@ impl<'tcx> BasicBlockData<'tcx> {
}
}

impl<O> PanicInfo<O> {
impl<O> AssertKind<O> {
/// Getting a description does not require `O` to be printable, and does not
/// require allocation.
/// The caller is expected to handle `BoundsCheck` separately.
pub fn description(&self) -> &'static str {
use PanicInfo::*;
use AssertKind::*;
match self {
Overflow(BinOp::Add) => "attempt to add with overflow",
Overflow(BinOp::Sub) => "attempt to subtract with overflow",
Expand All @@ -1419,14 +1419,14 @@ 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",
BoundsCheck { .. } => bug!("Unexpected PanicInfo"),
BoundsCheck { .. } => bug!("Unexpected AssertKind"),
}
}
}

impl<O: fmt::Debug> fmt::Debug for PanicInfo<O> {
impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use PanicInfo::*;
use AssertKind::*;
match self {
BoundsCheck { ref len, ref index } => {
write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index)
Expand Down Expand Up @@ -2719,7 +2719,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
}
}
Assert { ref cond, expected, ref msg, target, cleanup } => {
use PanicInfo::*;
use AssertKind::*;
let msg = match msg {
BoundsCheck { ref len, ref index } => {
BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder) }
Expand Down Expand Up @@ -2768,7 +2768,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
}
Assert { ref cond, ref msg, .. } => {
if cond.visit_with(visitor) {
use PanicInfo::*;
use AssertKind::*;
match msg {
BoundsCheck { ref len, ref index } => {
len.visit_with(visitor) || index.visit_with(visitor)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/visit.rs
Expand Up @@ -533,7 +533,7 @@ macro_rules! make_mir_visitor {
fn super_assert_message(&mut self,
msg: & $($mutability)? AssertMessage<'tcx>,
location: Location) {
use crate::mir::PanicInfo::*;
use crate::mir::AssertKind::*;
match msg {
BoundsCheck { len, index } => {
self.visit_operand(len, location);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_ssa/mir/block.rs
Expand Up @@ -11,7 +11,7 @@ use crate::MemFlags;

use rustc::middle::lang_items;
use rustc::mir;
use rustc::mir::PanicInfo;
use rustc::mir::AssertKind;
use rustc::ty::layout::{self, FnAbiExt, HasTyCtxt, LayoutOf};
use rustc::ty::{self, Instance, Ty, TypeFoldable};
use rustc_index::vec::Idx;
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// checked operation, just a comparison with the minimum
// value, so we have to check for the assert message.
if !bx.check_overflow() {
if let PanicInfo::OverflowNeg = *msg {
if let AssertKind::OverflowNeg = *msg {
const_cond = Some(expected);
}
}
Expand Down Expand Up @@ -412,7 +412,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

// Put together the arguments to the panic entry point.
let (lang_item, args) = match msg {
PanicInfo::BoundsCheck { ref len, ref index } => {
AssertKind::BoundsCheck { ref len, ref index } => {
let len = self.codegen_operand(&mut bx, len).immediate();
let index = self.codegen_operand(&mut bx, index).immediate();
(lang_items::PanicBoundsCheckFnLangItem, vec![location, index, len])
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/invalidation.rs
Expand Up @@ -153,8 +153,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
}
TerminatorKind::Assert { ref cond, expected: _, ref msg, target: _, cleanup: _ } => {
self.consume_operand(location, cond);
use rustc::mir::PanicInfo;
if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
use rustc::mir::AssertKind;
if let AssertKind::BoundsCheck { ref len, ref index } = *msg {
self.consume_operand(location, len);
self.consume_operand(location, index);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -654,8 +654,8 @@ impl<'cx, 'tcx> dataflow::generic::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt
}
TerminatorKind::Assert { ref cond, expected: _, ref msg, target: _, cleanup: _ } => {
self.consume_operand(loc, (cond, span), flow_state);
use rustc::mir::PanicInfo;
if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
use rustc::mir::AssertKind;
if let AssertKind::BoundsCheck { ref len, ref index } = *msg {
self.consume_operand(loc, (len, span), flow_state);
self.consume_operand(loc, (index, span), flow_state);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Expand Up @@ -11,7 +11,7 @@ use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
use rustc::mir::tcx::PlaceTy;
use rustc::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
use rustc::mir::PanicInfo;
use rustc::mir::AssertKind;
use rustc::mir::*;
use rustc::traits::query::type_op;
use rustc::traits::query::type_op::custom::CustomTypeOp;
Expand Down Expand Up @@ -1563,7 +1563,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
}

if let PanicInfo::BoundsCheck { ref len, ref index } = *msg {
if let AssertKind::BoundsCheck { ref len, ref index } = *msg {
if len.ty(body, tcx) != tcx.types.usize {
span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/const_eval/error.rs
@@ -1,7 +1,7 @@
use std::error::Error;
use std::fmt;

use rustc::mir::PanicInfo;
use rustc::mir::AssertKind;
use rustc_span::Symbol;

use super::InterpCx;
Expand All @@ -12,7 +12,7 @@ use crate::interpret::{ConstEvalErr, InterpError, InterpErrorInfo, Machine};
pub enum ConstEvalErrKind {
NeedsRfc(String),
ConstAccessesStatic,
AssertFailure(PanicInfo<u64>),
AssertFailure(AssertKind<u64>),
Panic { msg: Symbol, line: u32, col: u32, file: Symbol },
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/const_eval/machine.rs
Expand Up @@ -281,8 +281,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
msg: &AssertMessage<'tcx>,
_unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
use rustc::mir::PanicInfo::*;
// Convert `PanicInfo<Operand>` to `PanicInfo<u64>`.
use rustc::mir::AssertKind::*;
// Convert `AssertKind<Operand>` to `AssertKind<u64>`.
let err = match msg {
BoundsCheck { ref len, ref index } => {
let len = ecx
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -9,8 +9,8 @@ use rustc::mir::visit::{
MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor,
};
use rustc::mir::{
read_only, AggregateKind, BasicBlock, BinOp, Body, BodyAndCache, ClearCrossCrate, Constant,
Local, LocalDecl, LocalKind, Location, Operand, PanicInfo, Place, ReadOnlyBodyAndCache, Rvalue,
read_only, AggregateKind, AssertKind, BasicBlock, BinOp, Body, BodyAndCache, ClearCrossCrate,
Constant, Local, LocalDecl, LocalKind, Location, Operand, Place, ReadOnlyBodyAndCache, Rvalue,
SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind,
UnOp, RETURN_PLACE,
};
Expand Down Expand Up @@ -501,7 +501,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
}

fn report_panic_as_lint(&self, source_info: SourceInfo, panic: PanicInfo<u64>) -> Option<()> {
fn report_panic_as_lint(&self, source_info: SourceInfo, panic: AssertKind<u64>) -> Option<()> {
// Somewhat convoluted way to re-use the CTFE error reporting code.
let lint_root = self.lint_root(source_info)?;
let error = InterpError::MachineStop(Box::new(format!("{:?}", panic)));
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// `AssertKind` only has an `OverflowNeg` variant, to make sure that is
// appropriate to use.
assert_eq!(op, UnOp::Neg, "Neg is the only UnOp that can overflow");
self.report_panic_as_lint(source_info, PanicInfo::OverflowNeg)?;
self.report_panic_as_lint(source_info, AssertKind::OverflowNeg)?;
}

Some(())
Expand Down Expand Up @@ -572,7 +572,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
let (_res, overflow, _ty) = this.ecx.overflowing_binary_op(op, l, r)?;
Ok(overflow)
})? {
self.report_panic_as_lint(source_info, PanicInfo::Overflow(op))?;
self.report_panic_as_lint(source_info, AssertKind::Overflow(op))?;
}

Some(())
Expand Down Expand Up @@ -910,11 +910,11 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
span,
|lint| {
let msg = match msg {
PanicInfo::Overflow(_)
| PanicInfo::OverflowNeg
| PanicInfo::DivisionByZero
| PanicInfo::RemainderByZero => msg.description().to_owned(),
PanicInfo::BoundsCheck { ref len, ref index } => {
AssertKind::Overflow(_)
| AssertKind::OverflowNeg
| AssertKind::DivisionByZero
| AssertKind::RemainderByZero => msg.description().to_owned(),
AssertKind::BoundsCheck { ref len, ref index } => {
let len = self
.eval_operand(len, source_info)
.expect("len must be const");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/generator.rs
Expand Up @@ -1022,7 +1022,7 @@ fn create_generator_resume_function<'tcx>(

let mut cases = create_cases(body, &transform, Operation::Resume);

use rustc::mir::PanicInfo::{ResumedAfterPanic, ResumedAfterReturn};
use rustc::mir::AssertKind::{ResumedAfterPanic, ResumedAfterReturn};

// Jump to the entry point on the unresumed
cases.insert(0, (UNRESUMED, BasicBlock::new(0)));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/expr/as_place.rs
Expand Up @@ -5,7 +5,7 @@ use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use crate::hair::*;
use rustc::middle::region;
use rustc::mir::PanicInfo::BoundsCheck;
use rustc::mir::AssertKind::BoundsCheck;
use rustc::mir::*;
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt, Variance};
use rustc_span::Span;
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir_build/build/expr/as_rvalue.rs
Expand Up @@ -6,7 +6,7 @@ use crate::build::expr::category::{Category, RvalueFunc};
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use crate::hair::*;
use rustc::middle::region;
use rustc::mir::PanicInfo;
use rustc::mir::AssertKind;
use rustc::mir::*;
use rustc::ty::{self, Ty, UpvarSubsts};
use rustc_span::Span;
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
Operand::Move(is_min),
false,
PanicInfo::OverflowNeg,
AssertKind::OverflowNeg,
expr_span,
);
}
Expand Down Expand Up @@ -294,7 +294,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let val = tcx.mk_place_field(result_value.clone(), val_fld, ty);
let of = tcx.mk_place_field(result_value, of_fld, bool_ty);

let err = PanicInfo::Overflow(op);
let err = AssertKind::Overflow(op);

block = self.assert(block, Operand::Move(of), false, err, span);

Expand All @@ -305,11 +305,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// and 2. there are two possible failure cases, divide-by-zero and overflow.

let zero_err = if op == BinOp::Div {
PanicInfo::DivisionByZero
AssertKind::DivisionByZero
} else {
PanicInfo::RemainderByZero
AssertKind::RemainderByZero
};
let overflow_err = PanicInfo::Overflow(op);
let overflow_err = AssertKind::Overflow(op);

// Check for / 0
let is_zero = self.temp(bool_ty, span);
Expand Down

0 comments on commit ed2f22c

Please sign in to comment.