diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 32f90254a94..05264d32c6b 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -13,9 +13,9 @@ use rustc_target::abi::{Abi, Align, HasDataLayout, Size};
use tracing::{instrument, trace};
use super::{
- AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance, ImmTy, Immediate, InterpCx, InterpResult,
- Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer, Projectable, Provenance,
- Scalar, alloc_range, mir_assign_valid_types,
+ AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance, DiscardInterpError, ImmTy, Immediate,
+ InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer,
+ Projectable, Provenance, Scalar, alloc_range, mir_assign_valid_types,
};
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
@@ -490,9 +490,16 @@ where
// If an access is both OOB and misaligned, we want to see the bounds error.
// However we have to call `check_misalign` first to make the borrow checker happy.
let misalign_err = self.check_misalign(mplace.mplace.misaligned, CheckAlignMsg::BasedOn);
- let a = self.get_ptr_alloc_mut(mplace.ptr(), size)?;
- misalign_err?;
- Ok(a)
+ match self.get_ptr_alloc_mut(mplace.ptr(), size) {
+ Ok(a) => {
+ misalign_err?;
+ Ok(a)
+ }
+ Err(e) => {
+ misalign_err.discard_interp_err();
+ Err(e)
+ }
+ }
}
/// Turn a local in the current frame into a place.
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs
index 203cceccd9d..3c9fdd73100 100644
--- a/compiler/rustc_const_eval/src/interpret/validity.rs
+++ b/compiler/rustc_const_eval/src/interpret/validity.rs
@@ -17,8 +17,8 @@ use rustc_hir as hir;
use rustc_middle::bug;
use rustc_middle::mir::interpret::ValidationErrorKind::{self, *};
use rustc_middle::mir::interpret::{
- ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance,
- UnsupportedOpInfo, ValidationErrorInfo, alloc_range,
+ ExpectedKind, InterpError, InterpErrorInfo, InvalidMetaKind, Misalignment, PointerKind,
+ Provenance, UnsupportedOpInfo, ValidationErrorInfo, alloc_range,
};
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty};
@@ -95,16 +95,19 @@ macro_rules! try_validation {
Ok(x) => x,
// We catch the error and turn it into a validation failure. We are okay with
// allocation here as this can only slow down builds that fail anyway.
- Err(e) => match e.kind() {
- $(
- $($p)|+ =>
- throw_validation_failure!(
- $where,
- $kind
- )
- ),+,
- #[allow(unreachable_patterns)]
- _ => Err::(e)?,
+ Err(e) => {
+ let (kind, backtrace) = e.into_parts();
+ match kind {
+ $(
+ $($p)|+ => {
+ throw_validation_failure!(
+ $where,
+ $kind
+ )
+ }
+ ),+,
+ _ => Err::(InterpErrorInfo::from_parts(kind, backtrace))?,
+ }
}
}
}};
@@ -510,7 +513,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
Ub(DanglingIntPointer { addr: i, .. }) => DanglingPtrNoProvenance {
ptr_kind,
// FIXME this says "null pointer" when null but we need translate
- pointer: format!("{}", Pointer::