diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index fc04c7672db..280e75476b7 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -43,7 +43,7 @@ pub type ConstEvalResult<'tcx> = Result, ErrorHandled>; #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub struct ConstEvalErr<'tcx> { pub span: Span, - pub error: crate::mir::interpret::EvalErrorKind<'tcx, u64>, + pub error: crate::mir::interpret::InterpError<'tcx, u64>, pub stacktrace: Vec>, } @@ -135,10 +135,10 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { lint_root: Option, ) -> Result, ErrorHandled> { match self.error { - EvalErrorKind::Layout(LayoutError::Unknown(_)) | - EvalErrorKind::TooGeneric => return Err(ErrorHandled::TooGeneric), - EvalErrorKind::Layout(LayoutError::SizeOverflow(_)) | - EvalErrorKind::TypeckError => return Err(ErrorHandled::Reported), + InterpError::Layout(LayoutError::Unknown(_)) | + InterpError::TooGeneric => return Err(ErrorHandled::TooGeneric), + InterpError::Layout(LayoutError::SizeOverflow(_)) | + InterpError::TypeckError => return Err(ErrorHandled::Reported), _ => {}, } trace!("reporting const eval failure at {:?}", self.span); @@ -180,7 +180,7 @@ pub fn struct_error<'a, 'gcx, 'tcx>( #[derive(Debug, Clone)] pub struct EvalError<'tcx> { - pub kind: EvalErrorKind<'tcx, u64>, + pub kind: InterpError<'tcx, u64>, pub backtrace: Option>, } @@ -197,8 +197,8 @@ fn print_backtrace(backtrace: &mut Backtrace) { eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace); } -impl<'tcx> From> for EvalError<'tcx> { - fn from(kind: EvalErrorKind<'tcx, u64>) -> Self { +impl<'tcx> From> for EvalError<'tcx> { + fn from(kind: InterpError<'tcx, u64>) -> Self { let backtrace = match env::var("RUST_CTFE_BACKTRACE") { // matching RUST_BACKTRACE, we treat "0" the same as "not present". Ok(ref val) if val != "0" => { @@ -221,10 +221,10 @@ impl<'tcx> From> for EvalError<'tcx> { } } -pub type AssertMessage<'tcx> = EvalErrorKind<'tcx, mir::Operand<'tcx>>; +pub type AssertMessage<'tcx> = InterpError<'tcx, mir::Operand<'tcx>>; #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] -pub enum EvalErrorKind<'tcx, O> { +pub enum InterpError<'tcx, O> { /// This variant is used by machines to signal their own errors that do not /// match an existing variant. MachineError(String), @@ -312,9 +312,9 @@ pub enum EvalErrorKind<'tcx, O> { pub type EvalResult<'tcx, T = ()> = Result>; -impl<'tcx, O> EvalErrorKind<'tcx, O> { +impl<'tcx, O> InterpError<'tcx, O> { pub fn description(&self) -> &str { - use self::EvalErrorKind::*; + use self::InterpError::*; match *self { MachineError(ref inner) => inner, FunctionAbiMismatch(..) | FunctionArgMismatch(..) | FunctionRetMismatch(..) @@ -450,15 +450,15 @@ impl<'tcx> fmt::Display for EvalError<'tcx> { } } -impl<'tcx> fmt::Display for EvalErrorKind<'tcx, u64> { +impl<'tcx> fmt::Display for InterpError<'tcx, u64> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self) } } -impl<'tcx, O: fmt::Debug> fmt::Debug for EvalErrorKind<'tcx, O> { +impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use self::EvalErrorKind::*; + use self::InterpError::*; match *self { PointerOutOfBounds { ptr, check, allocation_size } => { write!(f, "Pointer must be in-bounds{} at offset {}, but is outside bounds of \ diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 0dd83168527..2c619a7a250 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -2,7 +2,7 @@ #[macro_export] macro_rules! err { - ($($tt:tt)*) => { Err($crate::mir::interpret::EvalErrorKind::$($tt)*.into()) }; + ($($tt:tt)*) => { Err($crate::mir::interpret::InterpError::$($tt)*.into()) }; } mod error; @@ -11,7 +11,7 @@ mod allocation; mod pointer; pub use self::error::{ - EvalError, EvalResult, EvalErrorKind, AssertMessage, ConstEvalErr, struct_error, + EvalError, EvalResult, InterpError, AssertMessage, ConstEvalErr, struct_error, FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, }; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 7b419e306db..a7ab0d6cb04 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -5,7 +5,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; use crate::hir::{self, HirId, InlineAsm}; -use crate::mir::interpret::{ConstValue, EvalErrorKind, Scalar}; +use crate::mir::interpret::{ConstValue, InterpError, Scalar}; use crate::mir::visit::MirVisitable; use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::Float; @@ -3226,8 +3226,8 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { target, cleanup, } => { - let msg = if let EvalErrorKind::BoundsCheck { ref len, ref index } = *msg { - EvalErrorKind::BoundsCheck { + let msg = if let InterpError::BoundsCheck { ref len, ref index } = *msg { + InterpError::BoundsCheck { len: len.fold_with(folder), index: index.fold_with(folder), } @@ -3301,7 +3301,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { ref cond, ref msg, .. } => { if cond.visit_with(visitor) { - if let EvalErrorKind::BoundsCheck { ref len, ref index } = *msg { + if let InterpError::BoundsCheck { ref len, ref index } = *msg { len.visit_with(visitor) || index.visit_with(visitor) } else { false diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 54e5bfc4397..4d44dc197cb 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -560,7 +560,7 @@ macro_rules! make_mir_visitor { fn super_assert_message(&mut self, msg: & $($mutability)? AssertMessage<'tcx>, location: Location) { - use crate::mir::interpret::EvalErrorKind::*; + use crate::mir::interpret::InterpError::*; if let BoundsCheck { len, index } = msg { self.visit_operand(len, location); self.visit_operand(index, location); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 26442faa321..53e8f7ed88b 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}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt}; use rustc::mir::{self, Place, PlaceBase, Static, StaticKind}; -use rustc::mir::interpret::EvalErrorKind; +use rustc::mir::interpret::InterpError; use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; use rustc_target::spec::abi::Abi; use rustc_mir::monomorphize; @@ -365,7 +365,7 @@ impl<'a, 'tcx: 'a, 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 mir::interpret::EvalErrorKind::OverflowNeg = *msg { + if let mir::interpret::InterpError::OverflowNeg = *msg { const_cond = Some(expected); } } @@ -400,7 +400,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Put together the arguments to the panic entry point. let (lang_item, args) = match *msg { - EvalErrorKind::BoundsCheck { ref len, ref index } => { + InterpError::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 5c159cda141..820a990c633 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -688,7 +688,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx cleanup: _, } => { self.consume_operand(ContextKind::Assert.new(loc), (cond, span), flow_state); - use rustc::mir::interpret::EvalErrorKind::BoundsCheck; + use rustc::mir::interpret::InterpError::BoundsCheck; if let BoundsCheck { ref len, ref index } = *msg { self.consume_operand(ContextKind::Assert.new(loc), (len, span), flow_state); self.consume_operand(ContextKind::Assert.new(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 aafbff35776..9f51fb9e969 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -215,7 +215,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> { cleanup: _, } => { self.consume_operand(ContextKind::Assert.new(location), cond); - use rustc::mir::interpret::EvalErrorKind::BoundsCheck; + use rustc::mir::interpret::InterpError::BoundsCheck; if let BoundsCheck { ref len, ref index } = *msg { self.consume_operand(ContextKind::Assert.new(location), len); self.consume_operand(ContextKind::Assert.new(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 3b559b28f12..5041a7ffee2 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -28,7 +28,7 @@ use rustc::infer::canonical::QueryRegionConstraint; use rustc::infer::outlives::env::RegionBoundPairs; use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin}; use rustc::infer::type_variable::TypeVariableOrigin; -use rustc::mir::interpret::{EvalErrorKind::BoundsCheck, ConstValue}; +use rustc::mir::interpret::{InterpError::BoundsCheck, ConstValue}; use rustc::mir::tcx::PlaceTy; use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext, NonMutatingUseContext}; use rustc::mir::*; diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 199d03ac445..f7cf0902013 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::EvalErrorKind::BoundsCheck; +use rustc::mir::interpret::InterpError::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 84f74484e60..7289dd96edb 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::EvalErrorKind; +use rustc::mir::interpret::InterpError; use rustc::mir::*; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use syntax_pos::Span; @@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block, Operand::Move(is_min), false, - EvalErrorKind::OverflowNeg, + InterpError::OverflowNeg, expr_span, ); } @@ -433,7 +433,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let val = result_value.clone().field(val_fld, ty); let of = result_value.field(of_fld, bool_ty); - let err = EvalErrorKind::Overflow(op); + let err = InterpError::Overflow(op); block = self.assert(block, Operand::Move(of), false, err, span); @@ -444,9 +444,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // and 2. there are two possible failure cases, divide-by-zero and overflow. let (zero_err, overflow_err) = if op == BinOp::Div { - (EvalErrorKind::DivisionByZero, EvalErrorKind::Overflow(op)) + (InterpError::DivisionByZero, InterpError::Overflow(op)) } else { - (EvalErrorKind::RemainderByZero, EvalErrorKind::Overflow(op)) + (InterpError::RemainderByZero, InterpError::Overflow(op)) }; // Check for / 0 diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 2268568c5f8..33715b749f9 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -23,7 +23,7 @@ use syntax::source_map::{Span, DUMMY_SP}; use crate::interpret::{self, PlaceTy, MPlaceTy, MemPlace, OpTy, ImmTy, Immediate, Scalar, Pointer, RawConst, ConstValue, - EvalResult, EvalError, EvalErrorKind, GlobalId, InterpretCx, StackPopCleanup, + EvalResult, EvalError, InterpError, GlobalId, InterpretCx, StackPopCleanup, Allocation, AllocId, MemoryKind, snapshot, RefTracking, }; @@ -173,7 +173,7 @@ fn eval_body_using_ecx<'mir, 'tcx>( impl<'tcx> Into> for ConstEvalError { fn into(self) -> EvalError<'tcx> { - EvalErrorKind::MachineError(self.to_string()).into() + InterpError::MachineError(self.to_string()).into() } } @@ -351,7 +351,7 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx> Ok(Some(match ecx.load_mir(instance.def) { Ok(mir) => mir, Err(err) => { - if let EvalErrorKind::NoMirFor(ref path) = err.kind { + if let InterpError::NoMirFor(ref path) = err.kind { return Err( ConstEvalError::NeedsRfc(format!("calling extern function `{}`", path)) .into(), @@ -679,7 +679,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( // any other kind of error will be reported to the user as a deny-by-default lint _ => if let Some(p) = cid.promoted { let span = tcx.optimized_mir(def_id).promoted[p].span; - if let EvalErrorKind::ReferencedConstant = err.error { + if let InterpError::ReferencedConstant = err.error { err.report_as_error( tcx.at(span), "evaluation of constant expression failed", diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index fe719bff250..5056d79bec4 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -4,7 +4,7 @@ use syntax::ast::{FloatTy, IntTy, UintTy}; use rustc_apfloat::ieee::{Single, Double}; use rustc::mir::interpret::{ - Scalar, EvalResult, Pointer, PointerArithmetic, EvalErrorKind, truncate + Scalar, EvalResult, Pointer, PointerArithmetic, InterpError, truncate }; use rustc::mir::CastKind; use rustc_apfloat::Float; @@ -85,7 +85,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> self.param_env, def_id, substs, - ).ok_or_else(|| EvalErrorKind::TooGeneric.into()); + ).ok_or_else(|| InterpError::TooGeneric.into()); let fn_ptr = self.memory.create_fn_alloc(instance?).with_default_tag(); self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?; } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 8b7e28c3de0..535fc58299b 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -16,7 +16,7 @@ use rustc_data_structures::indexed_vec::IndexVec; use rustc::mir::interpret::{ ErrorHandled, GlobalId, Scalar, FrameInfo, AllocId, - EvalResult, EvalErrorKind, + EvalResult, InterpError, truncate, sign_extend, }; use rustc_data_structures::fx::FxHashMap; @@ -167,7 +167,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf #[inline] fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) - .map_err(|layout| EvalErrorKind::Layout(layout).into()) + .map_err(|layout| InterpError::Layout(layout).into()) } } @@ -255,7 +255,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc self.param_env, def_id, substs, - ).ok_or_else(|| EvalErrorKind::TooGeneric.into()) + ).ok_or_else(|| InterpError::TooGeneric.into()) } pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool { @@ -647,8 +647,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc // `Memory::get_static_alloc` which has to use `const_eval_raw` to avoid cycles. let val = self.tcx.const_eval_raw(param_env.and(gid)).map_err(|err| { match err { - ErrorHandled::Reported => EvalErrorKind::ReferencedConstant, - ErrorHandled::TooGeneric => EvalErrorKind::TooGeneric, + ErrorHandled::Reported => InterpError::ReferencedConstant, + ErrorHandled::TooGeneric => InterpError::TooGeneric, } })?; self.raw_const_to_mplace(val) @@ -670,7 +670,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tc match self.stack[frame].locals[local].access() { Err(err) => { - if let EvalErrorKind::DeadLocal = err.kind { + if let InterpError::DeadLocal = err.kind { write!(msg, " is dead").unwrap(); } else { panic!("Failed to access local: {:?}", err); diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 99dd654df21..d9721a8cadf 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::{ - EvalResult, EvalErrorKind, Scalar, + EvalResult, InterpError, Scalar, }; use super::{ @@ -87,7 +87,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> let bits = self.read_scalar(args[0])?.to_bits(layout_of.size)?; let kind = match layout_of.abi { ty::layout::Abi::Scalar(ref scalar) => scalar.value, - _ => Err(::rustc::mir::interpret::EvalErrorKind::TypeNotPrimitive(ty))?, + _ => Err(::rustc::mir::interpret::InterpError::TypeNotPrimitive(ty))?, }; let out_val = if intrinsic_name.ends_with("_nonzero") { if bits == 0 { @@ -248,7 +248,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, '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(EvalErrorKind::Panic { msg, file, line, col }.into()); + return Err(InterpError::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) @@ -266,7 +266,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, '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(EvalErrorKind::Panic { msg, file, line, col }.into()); + return Err(InterpError::Panic { msg, file, line, col }.into()); } else { return Ok(false); } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 6ea200d4e4f..e5d8341dfcf 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -19,7 +19,7 @@ use syntax::ast::Mutability; use super::{ Pointer, AllocId, Allocation, GlobalId, AllocationExtra, - EvalResult, Scalar, EvalErrorKind, AllocKind, PointerArithmetic, + EvalResult, Scalar, InterpError, AllocKind, PointerArithmetic, Machine, AllocMap, MayLeak, ErrorHandled, InboundsCheck, }; @@ -344,8 +344,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { // no need to report anything, the const_eval call takes care of that for statics assert!(tcx.is_static(def_id).is_some()); match err { - ErrorHandled::Reported => EvalErrorKind::ReferencedConstant.into(), - ErrorHandled::TooGeneric => EvalErrorKind::TooGeneric.into(), + ErrorHandled::Reported => InterpError::ReferencedConstant.into(), + ErrorHandled::TooGeneric => InterpError::TooGeneric.into(), } }).map(|raw_const| { let allocation = tcx.alloc_map.lock().unwrap_memory(raw_const.alloc_id); @@ -458,7 +458,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { trace!("reading fn ptr: {}", ptr.alloc_id); match self.tcx.alloc_map.lock().get(ptr.alloc_id) { Some(AllocKind::Function(instance)) => Ok(instance), - _ => Err(EvalErrorKind::ExecuteMemory.into()), + _ => Err(InterpError::ExecuteMemory.into()), } } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 38a9371b927..7ea56e36474 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -9,7 +9,7 @@ use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerEx use rustc::mir::interpret::{ GlobalId, AllocId, InboundsCheck, ConstValue, Pointer, Scalar, - EvalResult, EvalErrorKind, + EvalResult, InterpError, sign_extend, truncate, }; use super::{ @@ -369,7 +369,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> let len = mplace.len(self)?; let bytes = self.memory.read_bytes(mplace.ptr, Size::from_bytes(len as u64))?; let str = ::std::str::from_utf8(bytes) - .map_err(|err| EvalErrorKind::ValidationFailure(err.to_string()))?; + .map_err(|err| InterpError::ValidationFailure(err.to_string()))?; Ok(str) } @@ -653,7 +653,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> .expect("tagged layout for non adt") .discriminants(self.tcx.tcx) .find(|(_, var)| var.val == real_discr) - .ok_or_else(|| EvalErrorKind::InvalidDiscriminant(raw_discr.erase_tag()))?; + .ok_or_else(|| InterpError::InvalidDiscriminant(raw_discr.erase_tag()))?; (real_discr, index.0) }, layout::DiscriminantKind::Niche { diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index 0168e1301fa..39054e359a4 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -12,7 +12,7 @@ use rustc::mir; use rustc::mir::interpret::{ AllocId, Pointer, Scalar, Relocations, Allocation, UndefMask, - EvalResult, EvalErrorKind, + EvalResult, InterpError, }; use rustc::ty::{self, TyCtxt}; @@ -78,7 +78,7 @@ impl<'a, 'mir, 'tcx> InfiniteLoopDetector<'a, 'mir, 'tcx> } // Second cycle - Err(EvalErrorKind::InfiniteLoop.into()) + Err(InterpError::InfiniteLoop.into()) } } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 01965f53c15..2080a329bb0 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -5,7 +5,7 @@ use rustc::ty::layout::{self, TyLayout, LayoutOf}; use syntax::source_map::Span; use rustc_target::spec::abi::Abi; -use rustc::mir::interpret::{EvalResult, PointerArithmetic, EvalErrorKind, Scalar}; +use rustc::mir::interpret::{EvalResult, PointerArithmetic, InterpError, Scalar}; use super::{ InterpretCx, Machine, Immediate, OpTy, ImmTy, PlaceTy, MPlaceTy, StackPopCleanup }; @@ -134,7 +134,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> self.goto_block(Some(target))?; } else { // Compute error message - use rustc::mir::interpret::EvalErrorKind::*; + use rustc::mir::interpret::InterpError::*; return match *msg { BoundsCheck { ref len, ref index } => { let len = self.read_immediate(self.eval_operand(len, None)?) @@ -212,7 +212,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M> return Ok(()); } let caller_arg = caller_arg.next() - .ok_or_else(|| EvalErrorKind::FunctionArgCountMismatch)?; + .ok_or_else(|| InterpError::FunctionArgCountMismatch)?; if rust_abi { debug_assert!(!caller_arg.layout.is_zst(), "ZSTs must have been already filtered out"); } diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 3323ec387bf..d4cf906619d 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -7,7 +7,7 @@ use rustc::ty::layout::{self, Size, Align, TyLayout, LayoutOf, VariantIdx}; use rustc::ty; use rustc_data_structures::fx::FxHashSet; use rustc::mir::interpret::{ - Scalar, AllocKind, EvalResult, EvalErrorKind, + Scalar, AllocKind, EvalResult, InterpError, }; use super::{ @@ -258,11 +258,11 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> match self.walk_value(op) { Ok(()) => Ok(()), Err(err) => match err.kind { - EvalErrorKind::InvalidDiscriminant(val) => + InterpError::InvalidDiscriminant(val) => validation_failure!( val, self.path, "a valid enum discriminant" ), - EvalErrorKind::ReadPointerAsBytes => + InterpError::ReadPointerAsBytes => validation_failure!( "a pointer", self.path, "plain (non-pointer) bytes" ), @@ -355,9 +355,9 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Err(err) => { error!("{:?} is not aligned to {:?}", ptr, align); match err.kind { - EvalErrorKind::InvalidNullPointerUsage => + InterpError::InvalidNullPointerUsage => return validation_failure!("NULL reference", self.path), - EvalErrorKind::AlignmentCheckFailed { required, has } => + InterpError::AlignmentCheckFailed { required, has } => return validation_failure!(format!("unaligned reference \ (required {} byte alignment but found {})", required.bytes(), has.bytes()), self.path), @@ -562,7 +562,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Err(err) => { // For some errors we might be able to provide extra information match err.kind { - EvalErrorKind::ReadUndefBytes(offset) => { + InterpError::ReadUndefBytes(offset) => { // Some byte was undefined, determine which // element that byte belongs to so we can // provide an index. diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index b3ef7407a7c..0d43602d899 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -7,7 +7,7 @@ use rustc::mir::{Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Loc use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind, Static, StaticKind}; use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem}; use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext}; -use rustc::mir::interpret::{EvalErrorKind, Scalar, GlobalId, EvalResult}; +use rustc::mir::interpret::{InterpError, Scalar, GlobalId, EvalResult}; use rustc::ty::{TyCtxt, self, Instance}; use syntax::source_map::{Span, DUMMY_SP}; use rustc::ty::subst::InternalSubsts; @@ -144,7 +144,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { Ok(val) => Some(val), Err(error) => { let diagnostic = error_to_const_error(&self.ecx, error); - use rustc::mir::interpret::EvalErrorKind::*; + use rustc::mir::interpret::InterpError::*; match diagnostic.error { // don't report these, they make no sense in a const prop context | MachineError(_) @@ -457,7 +457,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { ) } else { if overflow { - let err = EvalErrorKind::Overflow(op).into(); + let err = InterpError::Overflow(op).into(); let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); return None; } @@ -611,7 +611,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> { .hir() .as_local_hir_id(self.source.def_id()) .expect("some part of a failing const eval must be local"); - use rustc::mir::interpret::EvalErrorKind::*; + use rustc::mir::interpret::InterpError::*; let msg = match msg { Overflow(_) | OverflowNeg | diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index c4e303eb9aa..e63c1899fe5 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -773,7 +773,7 @@ fn create_generator_resume_function<'a, 'tcx>( let mut cases = create_cases(mir, &transform, |point| Some(point.resume)); - use rustc::mir::interpret::EvalErrorKind::{ + use rustc::mir::interpret::InterpError::{ GeneratorResumedAfterPanic, GeneratorResumedAfterReturn, };