mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Reuse the ctfe error emitting logic for the future incompat lint
This commit is contained in:
parent
dec05e9c73
commit
b05c790fd6
@ -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(())
|
||||
}
|
||||
|
@ -150,19 +150,18 @@ 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>`
|
||||
--> $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
|
||||
|
|
||||
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: 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 `UNALIGNED_READ`
|
||||
--> $DIR/ub-ref-ptr.rs:65:5
|
||||
|
|
||||
LL | ptr.read();
|
||||
| ^^^^^^^^^^
|
||||
= note: `#[deny(invalid_alignment)]` on by default
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
@ -171,18 +170,17 @@ For more information about this error, try `rustc --explain E0080`.
|
||||
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>`
|
||||
--> $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
|
||||
|
|
||||
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: 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 `UNALIGNED_READ`
|
||||
--> $DIR/ub-ref-ptr.rs:65:5
|
||||
|
|
||||
LL | ptr.read();
|
||||
| ^^^^^^^^^^
|
||||
= note: `#[deny(invalid_alignment)]` on by default
|
||||
|
||||
|
@ -150,19 +150,18 @@ 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>`
|
||||
--> $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
|
||||
|
|
||||
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: 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 `UNALIGNED_READ`
|
||||
--> $DIR/ub-ref-ptr.rs:65:5
|
||||
|
|
||||
LL | ptr.read();
|
||||
| ^^^^^^^^^^
|
||||
= note: `#[deny(invalid_alignment)]` on by default
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
@ -171,18 +170,17 @@ For more information about this error, try `rustc --explain E0080`.
|
||||
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>`
|
||||
--> $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
|
||||
|
|
||||
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: 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 `UNALIGNED_READ`
|
||||
--> $DIR/ub-ref-ptr.rs:65:5
|
||||
|
|
||||
LL | ptr.read();
|
||||
| ^^^^^^^^^^
|
||||
= note: `#[deny(invalid_alignment)]` on by default
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user