From 35417e722ba088b2b9dd832160f6194a64aa3277 Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Tue, 30 Jul 2019 20:18:50 +0530 Subject: [PATCH] renaming throw_err_* to throw_* --- src/librustc/mir/interpret/allocation.rs | 6 +-- src/librustc/mir/interpret/mod.rs | 20 ++++---- src/librustc/mir/interpret/pointer.rs | 6 +-- src/librustc/mir/interpret/value.rs | 12 ++--- src/librustc_mir/const_eval.rs | 6 +-- src/librustc_mir/interpret/cast.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 18 ++++---- src/librustc_mir/interpret/intern.rs | 4 +- src/librustc_mir/interpret/intrinsics.rs | 10 ++-- src/librustc_mir/interpret/machine.rs | 2 +- src/librustc_mir/interpret/memory.rs | 54 +++++++++++----------- src/librustc_mir/interpret/operand.rs | 10 ++-- src/librustc_mir/interpret/operator.rs | 12 ++--- src/librustc_mir/interpret/place.rs | 4 +- src/librustc_mir/interpret/step.rs | 2 +- src/librustc_mir/interpret/terminator.rs | 40 ++++++++-------- src/librustc_mir/interpret/validity.rs | 28 ++++++----- src/librustc_mir/transform/const_prop.rs | 2 +- 18 files changed, 112 insertions(+), 126 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index b8686754fa76..a9393561bfd0 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -244,7 +244,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size]) } // This includes the case where `offset` is out-of-bounds to begin with. - None => throw_err_unsup!(UnterminatedCString(ptr.erase_tag())), + None => throw_unsup!(UnterminatedCString(ptr.erase_tag())), } } @@ -446,7 +446,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation { if self.relocations(cx, ptr, size).is_empty() { Ok(()) } else { - throw_err_unsup!(ReadPointerAsBytes) + throw_unsup!(ReadPointerAsBytes) } } @@ -516,7 +516,7 @@ impl<'tcx, Tag, Extra> Allocation { self.undef_mask.is_range_defined( ptr.offset, ptr.offset + size, - ).or_else(|idx| throw_err_unsup!(ReadUndefBytes(idx))) + ).or_else(|idx| throw_unsup!(ReadUndefBytes(idx))) } pub fn mark_definedness( diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index bc72050de181..2409d22e5f0a 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -1,45 +1,45 @@ //! An interpreter for MIR used in CTFE and by miri #[macro_export] -macro_rules! throw_err_unsup { +macro_rules! throw_unsup { ($($tt:tt)*) => { - Err($crate::mir::interpret::InterpError::Unsupported( + return Err($crate::mir::interpret::InterpError::Unsupported( $crate::mir::interpret::UnsupportedOpInfo::$($tt)* ).into()) }; } #[macro_export] -macro_rules! throw_err_inval { +macro_rules! throw_inval { ($($tt:tt)*) => { - Err($crate::mir::interpret::InterpError::InvalidProgram( + return Err($crate::mir::interpret::InterpError::InvalidProgram( $crate::mir::interpret::InvalidProgramInfo::$($tt)* ).into()) }; } #[macro_export] -macro_rules! throw_err_ub { +macro_rules! throw_ub { ($($tt:tt)*) => { - Err($crate::mir::interpret::InterpError::UndefinedBehaviour( + return Err($crate::mir::interpret::InterpError::UndefinedBehaviour( $crate::mir::interpret::UndefinedBehaviourInfo::$($tt)* ).into()) }; } #[macro_export] -macro_rules! throw_err_panic { +macro_rules! throw_panic { ($($tt:tt)*) => { - Err($crate::mir::interpret::InterpError::Panic( + return Err($crate::mir::interpret::InterpError::Panic( $crate::mir::interpret::PanicInfo::$($tt)* ).into()) }; } #[macro_export] -macro_rules! throw_err_exhaust { +macro_rules! throw_exhaust { ($($tt:tt)*) => { - Err($crate::mir::interpret::InterpError::ResourceExhaustion( + return Err($crate::mir::interpret::InterpError::ResourceExhaustion( $crate::mir::interpret::ResourceExhaustionInfo::$($tt)* ).into()) }; diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index 17f963609f6d..0a9985133799 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -74,13 +74,13 @@ pub trait PointerArithmetic: layout::HasDataLayout { #[inline] fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_offset(val, i); - if over { throw_err_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) } + if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) } } #[inline] fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> { let (res, over) = self.overflowing_signed_offset(val, i128::from(i)); - if over { throw_err_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) } + if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) } } } @@ -196,7 +196,7 @@ impl<'tcx, Tag> Pointer { msg: CheckInAllocMsg, ) -> InterpResult<'tcx, ()> { if self.offset > allocation_size { - throw_err_unsup!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size }) + throw_unsup!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size }) } else { Ok(()) } diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 01db0e48e21e..607bcea7fe80 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -360,7 +360,7 @@ impl<'tcx, Tag> Scalar { Scalar::check_data(data, size); Ok(data) } - Scalar::Ptr(_) => throw_err_unsup!(ReadPointerAsBytes), + Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes), } } @@ -373,8 +373,8 @@ impl<'tcx, Tag> Scalar { #[inline] pub fn to_ptr(self) -> InterpResult<'tcx, Pointer> { match self { - Scalar::Raw { data: 0, .. } => throw_err_unsup!(InvalidNullPointerUsage), - Scalar::Raw { .. } => throw_err_unsup!(ReadBytesAsPointer), + Scalar::Raw { data: 0, .. } => throw_unsup!(InvalidNullPointerUsage), + Scalar::Raw { .. } => throw_unsup!(ReadBytesAsPointer), Scalar::Ptr(p) => Ok(p), } } @@ -406,7 +406,7 @@ impl<'tcx, Tag> Scalar { match self { Scalar::Raw { data: 0, size: 1 } => Ok(false), Scalar::Raw { data: 1, size: 1 } => Ok(true), - _ => throw_err_unsup!(InvalidBool), + _ => throw_unsup!(InvalidBool), } } @@ -414,7 +414,7 @@ impl<'tcx, Tag> Scalar { let val = self.to_u32()?; match ::std::char::from_u32(val) { Some(c) => Ok(c), - None => throw_err_unsup!(InvalidChar(val as u128)), + None => throw_unsup!(InvalidChar(val as u128)), } } @@ -537,7 +537,7 @@ impl<'tcx, Tag> ScalarMaybeUndef { pub fn not_undef(self) -> InterpResult<'static, Scalar> { match self { ScalarMaybeUndef::Scalar(scalar) => Ok(scalar), - ScalarMaybeUndef::Undef => throw_err_unsup!(ReadUndefBytes(Size::from_bytes(0))), + ScalarMaybeUndef::Undef => throw_unsup!(ReadUndefBytes(Size::from_bytes(0))), } } diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 423449bc95d4..75186b5fcf06 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -352,9 +352,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, ecx.goto_block(ret)?; // fully evaluated and done Ok(None) } else { - throw_err_unsup!( - MachineError(format!("calling non-const function `{}`", instance)) - ) + throw_unsup!(MachineError(format!("calling non-const function `{}`", instance))) }; } } @@ -414,7 +412,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, _tcx: TyCtxt<'tcx>, _def_id: DefId, ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> { - throw_err_unsup!(ReadForeignStatic) + throw_unsup!(ReadForeignStatic) } #[inline(always)] diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 94f3148aaaf9..9e87e112892c 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -199,7 +199,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }, // Casts to bool are not permitted by rustc, no need to handle them here. - _ => throw_err_unsup!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))), + _ => throw_unsup!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))), } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 61ee60fd3d50..cd057e059d50 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -135,7 +135,7 @@ pub enum LocalValue { impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> { pub fn access(&self) -> InterpResult<'tcx, Operand> { match self.value { - LocalValue::Dead => throw_err_unsup!(DeadLocal), + LocalValue::Dead => throw_unsup!(DeadLocal), LocalValue::Uninitialized => bug!("The type checker should prevent reading from a never-written local"), LocalValue::Live(val) => Ok(val), @@ -148,7 +148,7 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> { &mut self, ) -> InterpResult<'tcx, Result<&mut LocalValue, MemPlace>> { match self.value { - LocalValue::Dead => throw_err_unsup!(DeadLocal), + LocalValue::Dead => throw_unsup!(DeadLocal), LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)), ref mut local @ LocalValue::Live(Operand::Immediate(_)) | ref mut local @ LocalValue::Uninitialized => { @@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { &substs, )), None => if substs.needs_subst() { - throw_err_inval!(TooGeneric) + throw_inval!(TooGeneric) } else { Ok(substs) }, @@ -339,14 +339,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { && self.tcx.has_typeck_tables(did) && self.tcx.typeck_tables_of(did).tainted_by_errors { - return throw_err_inval!(TypeckError); + throw_inval!(TypeckError) } trace!("load mir {:?}", instance); match instance { ty::InstanceDef::Item(def_id) => if self.tcx.is_mir_available(did) { Ok(self.tcx.optimized_mir(did)) } else { - throw_err_unsup!(NoMirFor(self.tcx.def_path_str(def_id))) + throw_unsup!(NoMirFor(self.tcx.def_path_str(def_id))) }, _ => Ok(self.tcx.instance_mir(instance)), } @@ -359,7 +359,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match self.stack.last() { Some(frame) => Ok(self.monomorphize_with_substs(t, frame.instance.substs)?), None => if t.needs_subst() { - throw_err_inval!(TooGeneric).into() + throw_inval!(TooGeneric) } else { Ok(t) }, @@ -376,7 +376,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let substituted = t.subst(*self.tcx, substs); if substituted.needs_subst() { - return throw_err_inval!(TooGeneric); + throw_inval!(TooGeneric) } Ok(self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted)) @@ -575,7 +575,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { info!("ENTERING({}) {}", self.cur_frame(), self.frame().instance); if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit { - throw_err_exhaust!(StackFrameLimitReached) + throw_exhaust!(StackFrameLimitReached) } else { Ok(()) } @@ -623,7 +623,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } else { // Uh, that shouldn't happen... the function did not intend to return - return throw_err_ub!(Unreachable); + throw_ub!(Unreachable) } // Jump to new block -- *after* validation so that the spans make more sense. match frame.return_to_block { diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index 4539a1c7e1dd..1cc409d7a9ba 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -328,9 +328,7 @@ pub fn intern_const_alloc_recursive( } } else if ecx.memory().dead_alloc_map.contains_key(&alloc_id) { // dangling pointer - return throw_err_unsup!( - ValidationFailure("encountered dangling pointer in final constant".into()) - ) + throw_unsup!(ValidationFailure("encountered dangling pointer in final constant".into())) } } Ok(()) diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 687265c983f2..e5af9d86cb32 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -104,9 +104,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }; let out_val = if intrinsic_name.ends_with("_nonzero") { if bits == 0 { - return throw_err_unsup!( - Intrinsic(format!("{} called on 0", intrinsic_name)) - ); + throw_unsup!(Intrinsic(format!("{} called on 0", intrinsic_name))) } numeric_intrinsic(intrinsic_name.trim_end_matches("_nonzero"), bits, kind)? } else { @@ -192,9 +190,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if overflowed { let layout = self.layout_of(substs.type_at(0))?; let r_val = r.to_scalar()?.to_bits(layout.size)?; - return throw_err_unsup!(Intrinsic( - format!("Overflowing shift by {} in {}", r_val, intrinsic_name), - )); + throw_unsup!( + Intrinsic(format!("Overflowing shift by {} in {}", r_val, intrinsic_name)) + ) } self.write_scalar(val, dest)?; } diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 3f3d4376d29c..2e7e2ad93d44 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -251,6 +251,6 @@ pub trait Machine<'mir, 'tcx>: Sized { _mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer, ) -> InterpResult<'tcx, u64> { - throw_err_unsup!(ReadPointerAsBytes) + throw_unsup!(ReadPointerAsBytes) } } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 8c43fb3dc40d..949f9194d9ea 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -66,7 +66,7 @@ impl<'tcx, Other> FnVal<'tcx, Other> { match self { FnVal::Instance(instance) => Ok(instance), - FnVal::Other(_) => throw_err_unsup!(MachineError(format!( + FnVal::Other(_) => throw_unsup!(MachineError(format!( "Expected instance function pointer, got 'other' pointer" ))), } @@ -202,7 +202,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { kind: MemoryKind, ) -> InterpResult<'tcx, Pointer> { if ptr.offset.bytes() != 0 { - return throw_err_unsup!(ReallocateNonBasePtr); + throw_unsup!(ReallocateNonBasePtr) } // For simplicities' sake, we implement reallocate as "alloc, copy, dealloc". @@ -243,40 +243,38 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { trace!("deallocating: {}", ptr.alloc_id); if ptr.offset.bytes() != 0 { - return throw_err_unsup!(DeallocateNonBasePtr); + throw_unsup!(DeallocateNonBasePtr) } let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) { Some(alloc) => alloc, None => { // Deallocating static memory -- always an error - return match self.tcx.alloc_map.lock().get(ptr.alloc_id) { - Some(GlobalAlloc::Function(..)) => throw_err_unsup!(DeallocatedWrongMemoryKind( + match self.tcx.alloc_map.lock().get(ptr.alloc_id) { + Some(GlobalAlloc::Function(..)) => throw_unsup!(DeallocatedWrongMemoryKind( "function".to_string(), format!("{:?}", kind), )), Some(GlobalAlloc::Static(..)) | - Some(GlobalAlloc::Memory(..)) => throw_err_unsup!(DeallocatedWrongMemoryKind( + Some(GlobalAlloc::Memory(..)) => throw_unsup!(DeallocatedWrongMemoryKind( "static".to_string(), format!("{:?}", kind), )), - None => throw_err_unsup!(DoubleFree) + None => throw_unsup!(DoubleFree) } } }; if alloc_kind != kind { - return throw_err_unsup!(DeallocatedWrongMemoryKind( + throw_unsup!(DeallocatedWrongMemoryKind( format!("{:?}", alloc_kind), format!("{:?}", kind), - )); + )) } if let Some((size, align)) = old_size_and_align { if size.bytes() != alloc.bytes.len() as u64 || align != alloc.align { let bytes = Size::from_bytes(alloc.bytes.len() as u64); - return throw_err_unsup!( - IncorrectAllocationInformation(size, bytes, align, alloc.align) - ); + throw_unsup!(IncorrectAllocationInformation(size, bytes, align, alloc.align)) } } @@ -321,7 +319,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } else { // The biggest power of two through which `offset` is divisible. let offset_pow2 = 1 << offset.trailing_zeros(); - throw_err_unsup!(AlignmentCheckFailed { + throw_unsup!(AlignmentCheckFailed { has: Align::from_bytes(offset_pow2).unwrap(), required: align, }) @@ -343,7 +341,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { assert!(size.bytes() == 0); // Must be non-NULL and aligned. if bits == 0 { - return throw_err_unsup!(InvalidNullPointerUsage); + throw_unsup!(InvalidNullPointerUsage) } check_offset_align(bits, align)?; None @@ -364,10 +362,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // got picked we might be aligned even if this check fails. // We instead have to fall back to converting to an integer and checking // the "real" alignment. - return throw_err_unsup!(AlignmentCheckFailed { + throw_unsup!(AlignmentCheckFailed { has: alloc_align, - required: align, - }); + required: align + }) } check_offset_align(ptr.offset.bytes(), align)?; @@ -415,9 +413,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Some(GlobalAlloc::Memory(mem)) => Cow::Borrowed(mem), Some(GlobalAlloc::Function(..)) => - return throw_err_unsup!(DerefFunctionPointer), + throw_unsup!(DerefFunctionPointer), None => - return throw_err_unsup!(DanglingPointerDeref), + throw_unsup!(DanglingPointerDeref), Some(GlobalAlloc::Static(def_id)) => { // We got a "lazy" static that has not been computed yet. if tcx.is_foreign_item(def_id) { @@ -507,11 +505,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // to give us a cheap reference. let alloc = Self::get_static_alloc(memory_extra, tcx, id)?; if alloc.mutability == Mutability::Immutable { - return throw_err_unsup!(ModifiedConstantMemory); + throw_unsup!(ModifiedConstantMemory) } match M::STATIC_KIND { Some(kind) => Ok((MemoryKind::Machine(kind), alloc.into_owned())), - None => throw_err_unsup!(ModifiedStatic), + None => throw_unsup!(ModifiedStatic), } }); // Unpack the error type manually because type inference doesn't @@ -521,7 +519,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Ok(a) => { let a = &mut a.1; if a.mutability == Mutability::Immutable { - return throw_err_unsup!(ModifiedConstantMemory); + throw_unsup!(ModifiedConstantMemory) } Ok(a) } @@ -550,7 +548,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { if let Ok(_) = self.get_fn_alloc(id) { return if let AllocCheck::Dereferencable = liveness { // The caller requested no function pointers. - throw_err_unsup!(DerefFunctionPointer) + throw_unsup!(DerefFunctionPointer) } else { Ok((Size::ZERO, Align::from_bytes(1).unwrap())) }; @@ -581,7 +579,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { .expect("deallocated pointers should all be recorded in \ `dead_alloc_map`")) } else { - throw_err_unsup!(DanglingPointerDeref) + throw_unsup!(DanglingPointerDeref) }, } } @@ -593,7 +591,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } else { match self.tcx.alloc_map.lock().get(id) { Some(GlobalAlloc::Function(instance)) => Ok(FnVal::Instance(instance)), - _ => throw_err_unsup!(ExecuteMemory), + _ => throw_unsup!(ExecuteMemory), } } } @@ -604,7 +602,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { ) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> { let ptr = self.force_ptr(ptr)?; // We definitely need a pointer value. if ptr.offset.bytes() != 0 { - return throw_err_unsup!(InvalidFunctionPointer); + throw_unsup!(InvalidFunctionPointer) } self.get_fn_alloc(ptr.alloc_id) } @@ -839,9 +837,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { if (src.offset <= dest.offset && src.offset + size > dest.offset) || (dest.offset <= src.offset && dest.offset + size > src.offset) { - return throw_err_unsup!(Intrinsic( + throw_unsup!(Intrinsic( "copy_nonoverlapping called on overlapping ranges".to_string(), - )); + )) } } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 8c443c9579f7..402a9a5c5ce7 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -461,7 +461,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { mir_place.iterate(|place_base, place_projection| { let mut op = match place_base { PlaceBase::Local(mir::RETURN_PLACE) => - return throw_err_unsup!(ReadFromReturnPointer), + throw_unsup!(ReadFromReturnPointer), PlaceBase::Local(local) => { // Do not use the layout passed in as argument if the base we are looking at // here is not the entire place. @@ -534,7 +534,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match val.val { ConstValue::Param(_) => // FIXME(oli-obk): try to monomorphize - return throw_err_inval!(TooGeneric), + throw_inval!(TooGeneric), ConstValue::Unevaluated(def_id, substs) => { let instance = self.resolve(def_id, substs)?; return Ok(OpTy::from(self.const_eval_raw(GlobalId { @@ -610,7 +610,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let bits_discr = match raw_discr.to_bits(discr_val.layout.size) { Ok(raw_discr) => raw_discr, Err(_) => - return throw_err_unsup!(InvalidDiscriminant(raw_discr.erase_tag())), + throw_unsup!(InvalidDiscriminant(raw_discr.erase_tag())), }; let real_discr = if discr_val.layout.ty.is_signed() { // going from layout tag type to typeck discriminant type @@ -657,9 +657,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let ptr_valid = niche_start == 0 && variants_start == variants_end && !self.memory.ptr_may_be_null(ptr); if !ptr_valid { - return throw_err_unsup!( - InvalidDiscriminant(raw_discr.erase_tag().into()) - ); + throw_unsup!(InvalidDiscriminant(raw_discr.erase_tag().into())) } (dataful_variant.as_u32() as u128, dataful_variant) }, diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 334cf09ba122..a942da5771b0 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -155,7 +155,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { r, right_layout.ty ); - return throw_err_unsup!(Unimplemented(msg)); + throw_unsup!(Unimplemented(msg)) } // Operations that need special treatment for signed integers @@ -173,8 +173,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return Ok((Scalar::from_bool(op(&l, &r)), false)); } let op: Option (i128, bool)> = match bin_op { - Div if r == 0 => return throw_err_panic!(DivisionByZero), - Rem if r == 0 => return throw_err_panic!(RemainderByZero), + Div if r == 0 => throw_panic!(DivisionByZero), + Rem if r == 0 => throw_panic!(RemainderByZero), Div => Some(i128::overflowing_div), Rem => Some(i128::overflowing_rem), Add => Some(i128::overflowing_add), @@ -231,8 +231,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Add => u128::overflowing_add, Sub => u128::overflowing_sub, Mul => u128::overflowing_mul, - Div if r == 0 => return throw_err_panic!(DivisionByZero), - Rem if r == 0 => return throw_err_panic!(RemainderByZero), + Div if r == 0 => throw_panic!(DivisionByZero), + Rem if r == 0 => throw_panic!(RemainderByZero), Div => u128::overflowing_div, Rem => u128::overflowing_rem, _ => bug!(), @@ -250,7 +250,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { r, right_layout.ty, ); - return throw_err_unsup!(Unimplemented(msg)); + throw_unsup!(Unimplemented(msg)) } }; diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index b385862490a2..f66c4adf7639 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -356,7 +356,7 @@ where // This can be violated because this runs during promotion on code where the // type system has not yet ensured that such things don't happen. debug!("tried to access element {} of array/slice with length {}", field, len); - return throw_err_panic!(BoundsCheck { len, index: field }); + throw_panic!(BoundsCheck { len, index: field }); } stride * field } @@ -622,7 +622,7 @@ where .layout_of(self.monomorphize(self.frame().body.return_ty())?)?, } } - None => return throw_err_unsup!(InvalidNullPointerUsage), + None => throw_unsup!(InvalidNullPointerUsage), }, PlaceBase::Local(local) => PlaceTy { // This works even for dead/uninitialized locals; we check further when writing diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index de798ecee734..95824d0ebc16 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -121,7 +121,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // size of MIR constantly. Nop => {} - InlineAsm { .. } => return throw_err_unsup!(InlineAsm), + InlineAsm { .. } => throw_unsup!(InlineAsm), } self.stack[frame_idx].stmt += 1; diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index f1c91058b713..aa06922fb95f 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -19,7 +19,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.frame_mut().stmt = 0; Ok(()) } else { - throw_err_ub!(Unreachable) + throw_ub!(Unreachable) } } @@ -89,7 +89,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }, _ => { let msg = format!("can't handle callee of type {:?}", func.layout.ty); - return throw_err_unsup!(Unimplemented(msg)); + throw_unsup!(Unimplemented(msg)) } }; let args = self.eval_operands(args)?; @@ -136,7 +136,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } else { // Compute error message use rustc::mir::interpret::PanicInfo::*; - return match msg { + match msg { BoundsCheck { ref len, ref index } => { let len = self.read_immediate(self.eval_operand(len, None)?) .expect("can't eval len").to_scalar()? @@ -144,20 +144,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let index = self.read_immediate(self.eval_operand(index, None)?) .expect("can't eval index").to_scalar()? .to_bits(self.memory().pointer_size())? as u64; - throw_err_panic!(BoundsCheck { len, index }) + throw_panic!(BoundsCheck { len, index }) } Overflow(op) => - throw_err_panic!(Overflow(*op)), + throw_panic!(Overflow(*op)), OverflowNeg => - throw_err_panic!(OverflowNeg), + throw_panic!(OverflowNeg), DivisionByZero => - throw_err_panic!(DivisionByZero), + throw_panic!(DivisionByZero), RemainderByZero => - throw_err_panic!(RemainderByZero), + throw_panic!(RemainderByZero), GeneratorResumedAfterReturn => - throw_err_panic!(GeneratorResumedAfterReturn), + throw_panic!(GeneratorResumedAfterReturn), GeneratorResumedAfterPanic => - throw_err_panic!(GeneratorResumedAfterPanic), + throw_panic!(GeneratorResumedAfterPanic), Panic { .. } => bug!("`Panic` variant cannot occur in MIR"), }; @@ -173,7 +173,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { `simplify_branches` mir pass"), FalseUnwind { .. } => bug!("should have been eliminated by\ `simplify_branches` mir pass"), - Unreachable => return throw_err_ub!(Unreachable), + Unreachable => throw_ub!(Unreachable), } Ok(()) @@ -226,9 +226,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } // Now, check if !Self::check_argument_compat(rust_abi, caller_arg.layout, callee_arg.layout) { - return throw_err_unsup!( - FunctionArgMismatch(caller_arg.layout.ty, callee_arg.layout.ty) - ); + throw_unsup!(FunctionArgMismatch(caller_arg.layout.ty, callee_arg.layout.ty)) } // We allow some transmutes here self.copy_op_transmute(caller_arg, callee_arg) @@ -256,13 +254,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match instance.def { ty::InstanceDef::Intrinsic(..) => { if caller_abi != Abi::RustIntrinsic { - return throw_err_unsup!(FunctionAbiMismatch(caller_abi, Abi::RustIntrinsic)); + throw_unsup!(FunctionAbiMismatch(caller_abi, Abi::RustIntrinsic)) } // The intrinsic itself cannot diverge, so if we got here without a return // place... (can happen e.g., for transmute returning `!`) let dest = match dest { Some(dest) => dest, - None => return throw_err_ub!(Unreachable) + None => throw_ub!(Unreachable) }; M::call_intrinsic(self, instance, args, dest)?; // No stack frame gets pushed, the main loop will just act as if the @@ -297,7 +295,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { abi, }; if normalize_abi(caller_abi) != normalize_abi(callee_abi) { - return throw_err_unsup!(FunctionAbiMismatch(caller_abi, callee_abi)); + throw_unsup!(FunctionAbiMismatch(caller_abi, callee_abi)) } } @@ -392,7 +390,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Now we should have no more caller args if caller_iter.next().is_some() { trace!("Caller has passed too many args"); - return throw_err_unsup!(FunctionArgCountMismatch); + throw_unsup!(FunctionArgCountMismatch) } // Don't forget to check the return type! if let Some(caller_ret) = dest { @@ -404,15 +402,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { caller_ret.layout, callee_ret.layout, ) { - return throw_err_unsup!( + throw_unsup!( FunctionRetMismatch(caller_ret.layout.ty, callee_ret.layout.ty) - ); + ) } } else { let local = mir::RETURN_PLACE; let ty = self.frame().body.local_decls[local].ty; if !self.tcx.is_ty_uninhabited_from_any_module(ty) { - return throw_err_unsup!(FunctionRetMismatch(self.tcx.types.never, ty)); + throw_unsup!(FunctionRetMismatch(self.tcx.types.never, ty)) } } Ok(()) diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index df6fb7a7c63c..aa2461729641 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -22,7 +22,7 @@ macro_rules! validation_failure { } else { format!(" at {}", where_) }; - throw_err_unsup!(ValidationFailure(format!( + throw_unsup!(ValidationFailure(format!( "encountered {}{}, but expected {}", $what, where_, $details, ))) @@ -34,7 +34,7 @@ macro_rules! validation_failure { } else { format!(" at {}", where_) }; - throw_err_unsup!(ValidationFailure(format!( + throw_unsup!(ValidationFailure(format!( "encountered {}{}", $what, where_, ))) @@ -45,14 +45,14 @@ macro_rules! try_validation { ($e:expr, $what:expr, $where:expr, $details:expr) => {{ match $e { Ok(x) => x, - Err(_) => return validation_failure!($what, $where, $details), + Err(_) => validation_failure!($what, $where, $details), } }}; ($e:expr, $what:expr, $where:expr) => {{ match $e { Ok(x) => x, - Err(_) => return validation_failure!($what, $where), + Err(_) => validation_failure!($what, $where), } }} } @@ -408,18 +408,18 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> use super::UnsupportedOpInfo::*; match err.kind { InterpError::Unsupported(InvalidNullPointerUsage) => - return validation_failure!("NULL reference", self.path), + validation_failure!("NULL reference", self.path), InterpError::Unsupported(AlignmentCheckFailed { required, has }) => - return validation_failure!(format!("unaligned reference \ + validation_failure!(format!("unaligned reference \ (required {} byte alignment but found {})", required.bytes(), has.bytes()), self.path), InterpError::Unsupported(ReadBytesAsPointer) => - return validation_failure!( + validation_failure!( "dangling reference (created from integer)", self.path ), _ => - return validation_failure!( + validation_failure!( "dangling reference (not entirely in bounds)", self.path ), @@ -512,27 +512,27 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> if lo == 1 && hi == max_hi { // Only NULL is the niche. So make sure the ptr is NOT NULL. if self.ecx.memory.ptr_may_be_null(ptr) { - return validation_failure!( + validation_failure!( "a potentially NULL pointer", self.path, format!( "something that cannot possibly fail to be {}", wrapping_range_format(&layout.valid_range, max_hi) ) - ); + ) } return Ok(()); } else { // Conservatively, we reject, because the pointer *could* have a bad // value. - return validation_failure!( + validation_failure!( "a pointer", self.path, format!( "something that cannot possibly fail to be {}", wrapping_range_format(&layout.valid_range, max_hi) ) - ); + ) } } Ok(data) => @@ -616,9 +616,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> let i = (offset.bytes() / ty_size.bytes()) as usize; self.path.push(PathElem::ArrayElem(i)); - return validation_failure!( - "undefined bytes", self.path - ) + validation_failure!("undefined bytes", self.path) }, // Other errors shouldn't be possible _ => return Err(err), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index db6b62e95ce0..807a7e88498b 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -441,7 +441,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // Need to do overflow check here: For actual CTFE, MIR // generation emits code that does this before calling the op. if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) { - return throw_err_panic!(OverflowNeg); + throw_panic!(OverflowNeg) } } UnOp::Not => {