diff options
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/machine.rs | 39 | ||||
| -rw-r--r-- | src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr | 34 | ||||
| -rw-r--r-- | src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr | 34 |
3 files changed, 54 insertions, 53 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 50776d65551..abe06737def 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,7 +1,7 @@ use rustc_hir::def::DefKind; use rustc_hir::{LangItem, CRATE_HIR_ID}; use rustc_middle::mir; -use rustc_middle::mir::interpret::{PointerArithmetic, UndefinedBehaviorInfo}; +use rustc_middle::mir::interpret::{InterpError, PointerArithmetic, UndefinedBehaviorInfo}; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::lint::builtin::INVALID_ALIGNMENT; @@ -353,22 +353,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, ecx.cur_span(), "`alignment_check_failed` called when no alignment check requested" ), - CheckAlignment::FutureIncompat => ecx.tcx.struct_span_lint_hir( - INVALID_ALIGNMENT, - ecx.stack().iter().find_map(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID), - ecx.cur_span(), - UndefinedBehaviorInfo::AlignmentCheckFailed { has, required }.to_string(), - |db| { - let mut stacktrace = ecx.generate_stacktrace(); - // Filter out `requires_caller_location` frames. - stacktrace - .retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx)); - for frame in stacktrace { - db.span_label(frame.span, format!("inside `{}`", frame.instance)); - } - db - }, - ), + CheckAlignment::FutureIncompat => { + let err = ConstEvalErr::new( + ecx, + InterpError::UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { + has, + required, + }) + .into(), + None, + ); + ecx.tcx.struct_span_lint_hir( + INVALID_ALIGNMENT, + ecx.stack().iter().find_map(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID), + err.span, + err.error.to_string(), + |db| { + err.decorate(db, |_| {}); + db + }, + ); + } } Ok(()) } diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr index 6e6cbb34aeb..a0a8d76d10d 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr @@ -151,18 +151,17 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; error: accessing memory with alignment 1, but alignment 4 is required --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | - = note: inside `std::ptr::read::<u32>` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL - | - = note: inside `ptr::const_ptr::<impl *const u32>::read` - | - ::: $DIR/ub-ref-ptr.rs:65:5 +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 | LL | ptr.read(); - | ---------- inside `UNALIGNED_READ` - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> + | ^^^^^^^^^^ = note: `#[deny(invalid_alignment)]` on by default error: aborting due to 15 previous errors @@ -172,17 +171,16 @@ Future incompatibility report: Future breakage diagnostic: error: accessing memory with alignment 1, but alignment 4 is required --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | - = note: inside `std::ptr::read::<u32>` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL - | - = note: inside `ptr::const_ptr::<impl *const u32>::read` - | - ::: $DIR/ub-ref-ptr.rs:65:5 +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 | LL | ptr.read(); - | ---------- inside `UNALIGNED_READ` - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> + | ^^^^^^^^^^ = note: `#[deny(invalid_alignment)]` on by default diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr index 3d1f36f0012..d53b44671e3 100644 --- a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr @@ -151,18 +151,17 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) }; error: accessing memory with alignment 1, but alignment 4 is required --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | - = note: inside `std::ptr::read::<u32>` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL - | - = note: inside `ptr::const_ptr::<impl *const u32>::read` - | - ::: $DIR/ub-ref-ptr.rs:65:5 +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 | LL | ptr.read(); - | ---------- inside `UNALIGNED_READ` - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> + | ^^^^^^^^^^ = note: `#[deny(invalid_alignment)]` on by default error: aborting due to 15 previous errors @@ -172,17 +171,16 @@ Future incompatibility report: Future breakage diagnostic: error: accessing memory with alignment 1, but alignment 4 is required --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | - = note: inside `std::ptr::read::<u32>` + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> +note: inside `std::ptr::read::<u32>` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `ptr::const_ptr::<impl *const u32>::read` --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL - | - = note: inside `ptr::const_ptr::<impl *const u32>::read` - | - ::: $DIR/ub-ref-ptr.rs:65:5 +note: inside `UNALIGNED_READ` + --> $DIR/ub-ref-ptr.rs:65:5 | LL | ptr.read(); - | ---------- inside `UNALIGNED_READ` - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616> + | ^^^^^^^^^^ = note: `#[deny(invalid_alignment)]` on by default |
