rename PanicInfo -> AssertKind
This commit is contained in:
parent
7e7d1c39ed
commit
ed2f22c5a9
12 changed files with 41 additions and 41 deletions
|
|
@ -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,
|
||||
|
|
@ -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>>;
|
||||
|
|
@ -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",
|
||||
|
|
@ -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)
|
||||
|
|
@ -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) }
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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 },
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
@ -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)));
|
||||
|
|
@ -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(())
|
||||
|
|
@ -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(())
|
||||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -86,7 +86,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
Operand::Move(is_min),
|
||||
false,
|
||||
PanicInfo::OverflowNeg,
|
||||
AssertKind::OverflowNeg,
|
||||
expr_span,
|
||||
);
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue