From 654519d3c5cd0bdece35a3282bdb433bf945ee57 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Mon, 29 Jul 2019 13:28:55 +0530 Subject: [PATCH] use PanicInfo and UnsupportedOpInfo --- src/librustc/mir/interpret/error.rs | 16 ++++++++-------- src/librustc/mir/interpret/mod.rs | 4 ++-- src/librustc/mir/mod.rs | 6 +++--- src/librustc/mir/visit.rs | 2 +- src/librustc_codegen_ssa/mir/block.rs | 6 +++--- src/librustc_mir/borrow_check/mod.rs | 4 ++-- .../borrow_check/nll/invalidation.rs | 4 ++-- .../borrow_check/nll/type_check/mod.rs | 4 ++-- src/librustc_mir/build/expr/as_place.rs | 2 +- src/librustc_mir/build/expr/as_rvalue.rs | 12 ++++++------ src/librustc_mir/interpret/intrinsics.rs | 6 +++--- src/librustc_mir/interpret/terminator.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 14 +++++++------- src/librustc_mir/transform/generator.rs | 2 +- 14 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index e519a83c0266..5a464ddd383c 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -237,7 +237,7 @@ impl<'tcx> From> for InterpErrorInfo<'tcx> { } #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] -pub enum PanicMessage { +pub enum PanicInfo { Panic { msg: Symbol, line: u32, @@ -257,14 +257,14 @@ pub enum PanicMessage { } /// Type for MIR `Assert` terminator error messages. -pub type AssertMessage<'tcx> = PanicMessage>; +pub type AssertMessage<'tcx> = PanicInfo>; -impl PanicMessage { +impl PanicInfo { /// 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. pub fn description(&self) -> &'static str { - use PanicMessage::*; + use PanicInfo::*; match self { Overflow(mir::BinOp::Add) => "attempt to add with overflow", @@ -293,14 +293,14 @@ impl PanicMessage { GeneratorResumedAfterPanic => "generator resumed after panicking", Panic { .. } | BoundsCheck { .. } => - bug!("Unexpected PanicMessage"), + bug!("Unexpected PanicInfo"), } } } -impl fmt::Debug for PanicMessage { +impl fmt::Debug for PanicInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use PanicMessage::*; + use PanicInfo::*; match self { Panic { ref msg, line, col, ref file } => write!(f, "the evaluated program panicked at '{}', {}:{}:{}", msg, file, line, col), @@ -568,7 +568,7 @@ impl fmt::Debug for ResourceExhaustionInfo { #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum InterpError<'tcx> { /// The program panicked. - Panic(PanicMessage), + Panic(PanicInfo), /// The program caused undefined behavior. UndefinedBehaviour(UndefinedBehaviourInfo), /// The program did something the interpreter does not support (some of these *might* be UB diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index c4a3bbfc28b1..4b09da87d314 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -31,7 +31,7 @@ macro_rules! err_ub { macro_rules! err_panic { ($($tt:tt)*) => { Err($crate::mir::interpret::InterpError::Panic( - $crate::mir::interpret::PanicMessage::$($tt)* + $crate::mir::interpret::PanicInfo::$($tt)* ).into()) }; } @@ -52,7 +52,7 @@ mod pointer; pub use self::error::{ InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error, - FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicMessage, UnsupportedInfo, + FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicInfo, UnsupportedInfo, InvalidProgramInfo, ResourceExhaustionInfo, UndefinedBehaviourInfo, }; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 50f16858c048..1e2ec08301cf 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -7,7 +7,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; use crate::hir::{self, InlineAsm as HirInlineAsm}; -use crate::mir::interpret::{ConstValue, PanicMessage, Scalar}; +use crate::mir::interpret::{ConstValue, PanicInfo, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; @@ -3152,7 +3152,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } } Assert { ref cond, expected, ref msg, target, cleanup } => { - use PanicMessage::*; + use PanicInfo::*; let msg = match msg { BoundsCheck { ref len, ref index } => BoundsCheck { @@ -3200,7 +3200,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } Assert { ref cond, ref msg, .. } => { if cond.visit_with(visitor) { - use PanicMessage::*; + use PanicInfo::*; match msg { BoundsCheck { ref len, ref index } => len.visit_with(visitor) || index.visit_with(visitor), diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 7562981f94f6..ee4ecb6762c9 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -514,7 +514,7 @@ macro_rules! make_mir_visitor { fn super_assert_message(&mut self, msg: & $($mutability)? AssertMessage<'tcx>, location: Location) { - use crate::mir::interpret::PanicMessage::*; + use crate::mir::interpret::PanicInfo::*; match msg { BoundsCheck { len, index } => { self.visit_operand(len, location); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 18611c3e167d..006ebcbdec67 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -2,7 +2,7 @@ use rustc::middle::lang_items; use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt}; use rustc::mir::{self, Place, PlaceBase, Static, StaticKind}; -use rustc::mir::interpret::PanicMessage; +use rustc::mir::interpret::PanicInfo; use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; use rustc_target::spec::abi::Abi; use crate::base; @@ -368,7 +368,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 PanicMessage::OverflowNeg = *msg { + if let PanicInfo::OverflowNeg = *msg { const_cond = Some(expected); } } @@ -403,7 +403,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 { - PanicMessage::BoundsCheck { ref len, ref index } => { + PanicInfo::BoundsCheck { ref len, ref index } => { let len = self.codegen_operand(&mut bx, len).immediate(); let index = self.codegen_operand(&mut bx, index).immediate(); diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 92774bbb7a6b..2be39799b527 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -733,8 +733,8 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx cleanup: _, } => { self.consume_operand(loc, (cond, span), flow_state); - use rustc::mir::interpret::PanicMessage; - if let PanicMessage::BoundsCheck { ref len, ref index } = *msg { + use rustc::mir::interpret::PanicInfo; + if let PanicInfo::BoundsCheck { ref len, ref index } = *msg { self.consume_operand(loc, (len, span), flow_state); self.consume_operand(loc, (index, span), flow_state); } diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index aa9e68bd7de4..631a81421131 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -207,8 +207,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { cleanup: _, } => { self.consume_operand(location, cond); - use rustc::mir::interpret::PanicMessage; - if let PanicMessage::BoundsCheck { ref len, ref index } = *msg { + use rustc::mir::interpret::PanicInfo; + if let PanicInfo::BoundsCheck { ref len, ref index } = *msg { self.consume_operand(location, len); self.consume_operand(location, index); } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 50c0640f885f..f10d505fe898 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -26,7 +26,7 @@ use rustc::infer::canonical::QueryRegionConstraints; use rustc::infer::outlives::env::RegionBoundPairs; use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc::mir::interpret::{ConstValue, PanicMessage}; +use rustc::mir::interpret::{ConstValue, PanicInfo}; use rustc::mir::tcx::PlaceTy; use rustc::mir::visit::{PlaceContext, Visitor, NonMutatingUseContext}; use rustc::mir::*; @@ -1632,7 +1632,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } - if let PanicMessage::BoundsCheck { ref len, ref index } = *msg { + if let PanicInfo::BoundsCheck { ref len, ref index } = *msg { if len.ty(body, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 7a428a2ec9f3..7005f274e0e7 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -4,7 +4,7 @@ use crate::build::expr::category::Category; use crate::build::ForGuard::{OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; -use rustc::mir::interpret::{PanicMessage::BoundsCheck}; +use rustc::mir::interpret::{PanicInfo::BoundsCheck}; use rustc::mir::*; use rustc::ty::{CanonicalUserTypeAnnotation, Variance}; diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 92daf06e6f8f..ec061e745357 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -7,7 +7,7 @@ use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::hair::*; use rustc::middle::region; -use rustc::mir::interpret::PanicMessage; +use rustc::mir::interpret::PanicInfo; use rustc::mir::*; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use syntax_pos::Span; @@ -101,7 +101,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, Operand::Move(is_min), false, - PanicMessage::OverflowNeg, + PanicInfo::OverflowNeg, expr_span, ); } @@ -401,7 +401,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let val = result_value.clone().field(val_fld, ty); let of = result_value.field(of_fld, bool_ty); - let err = PanicMessage::Overflow(op); + let err = PanicInfo::Overflow(op); block = self.assert(block, Operand::Move(of), false, err, span); @@ -412,11 +412,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 { - PanicMessage::DivisionByZero + PanicInfo::DivisionByZero } else { - PanicMessage::RemainderByZero + PanicInfo::RemainderByZero }; - let overflow_err = PanicMessage::Overflow(op); + let overflow_err = PanicInfo::Overflow(op); // Check for / 0 let is_zero = self.temp(bool_ty, span); diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index f943ff67c085..9605395b84b1 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -7,7 +7,7 @@ use rustc::ty; use rustc::ty::layout::{LayoutOf, Primitive, Size}; use rustc::mir::BinOp; use rustc::mir::interpret::{ - InterpResult, InterpError, Scalar, PanicMessage, UnsupportedInfo::*, + InterpResult, InterpError, Scalar, PanicInfo, UnsupportedInfo::*, }; use super::{ @@ -250,7 +250,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic(PanicMessage::Panic { msg, file, line, col }).into()); + return Err(InterpError::Panic(PanicInfo::Panic { msg, file, line, col }).into()); } else if Some(def_id) == self.tcx.lang_items().begin_panic_fn() { assert!(args.len() == 2); // &'static str, &(&'static str, u32, u32) @@ -268,7 +268,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let file = Symbol::intern(self.read_str(file_place)?); let line = self.read_scalar(line.into())?.to_u32()?; let col = self.read_scalar(col.into())?.to_u32()?; - return Err(InterpError::Panic(PanicMessage::Panic { msg, file, line, col }).into()); + return Err(InterpError::Panic(PanicInfo::Panic { msg, file, line, col }).into()); } else { return Ok(false); } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index b7dbc8384586..14b92f2b3d49 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -136,7 +136,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.goto_block(Some(target))?; } else { // Compute error message - use rustc::mir::interpret::PanicMessage::*; + use rustc::mir::interpret::PanicInfo::*; return match msg { BoundsCheck { ref len, ref index } => { let len = self.read_immediate(self.eval_operand(len, None)?) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 9918356d355b..ec8a33f7a43f 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -13,7 +13,7 @@ use rustc::mir::{ use rustc::mir::visit::{ Visitor, PlaceContext, MutatingUseContext, MutVisitor, NonMutatingUseContext, }; -use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, InterpError, PanicMessage}; +use rustc::mir::interpret::{Scalar, GlobalId, InterpResult, InterpError, PanicInfo}; use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; use syntax_pos::{Span, DUMMY_SP}; use rustc::ty::subst::InternalSubsts; @@ -526,7 +526,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) } else { if overflow { - let err = InterpError::Panic(PanicMessage::Overflow(op)).into(); + let err = InterpError::Panic(PanicInfo::Overflow(op)).into(); let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); return None; } @@ -763,12 +763,12 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { .as_local_hir_id(self.source.def_id()) .expect("some part of a failing const eval must be local"); let msg = match msg { - PanicMessage::Overflow(_) | - PanicMessage::OverflowNeg | - PanicMessage::DivisionByZero | - PanicMessage::RemainderByZero => + PanicInfo::Overflow(_) | + PanicInfo::OverflowNeg | + PanicInfo::DivisionByZero | + PanicInfo::RemainderByZero => msg.description().to_owned(), - PanicMessage::BoundsCheck { ref len, ref index } => { + PanicInfo::BoundsCheck { ref len, ref index } => { let len = self .eval_operand(len, source_info) .expect("len must be const"); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 5461a2e470c7..94bb70e10aa5 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -1016,7 +1016,7 @@ fn create_generator_resume_function<'tcx>( let mut cases = create_cases(body, &transform, |point| Some(point.resume)); - use rustc::mir::interpret::PanicMessage::{ + use rustc::mir::interpret::PanicInfo::{ GeneratorResumedAfterPanic, GeneratorResumedAfterReturn, };