Reuse the ctfe error emitting logic for the future incompat lint
This commit is contained in:
parent
dec05e9c73
commit
b05c790fd6
3 changed files with 58 additions and 57 deletions
|
@ -1,7 +1,7 @@
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::{LangItem, CRATE_HIR_ID};
|
use rustc_hir::{LangItem, CRATE_HIR_ID};
|
||||||
use rustc_middle::mir;
|
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::layout::FnAbiOf;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_session::lint::builtin::INVALID_ALIGNMENT;
|
use rustc_session::lint::builtin::INVALID_ALIGNMENT;
|
||||||
|
@ -353,22 +353,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
||||||
ecx.cur_span(),
|
ecx.cur_span(),
|
||||||
"`alignment_check_failed` called when no alignment check requested"
|
"`alignment_check_failed` called when no alignment check requested"
|
||||||
),
|
),
|
||||||
CheckAlignment::FutureIncompat => ecx.tcx.struct_span_lint_hir(
|
CheckAlignment::FutureIncompat => {
|
||||||
INVALID_ALIGNMENT,
|
let err = ConstEvalErr::new(
|
||||||
ecx.stack().iter().find_map(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID),
|
ecx,
|
||||||
ecx.cur_span(),
|
InterpError::UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed {
|
||||||
UndefinedBehaviorInfo::AlignmentCheckFailed { has, required }.to_string(),
|
has,
|
||||||
|db| {
|
required,
|
||||||
let mut stacktrace = ecx.generate_stacktrace();
|
})
|
||||||
// Filter out `requires_caller_location` frames.
|
.into(),
|
||||||
stacktrace
|
None,
|
||||||
.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
|
);
|
||||||
for frame in stacktrace {
|
ecx.tcx.struct_span_lint_hir(
|
||||||
db.span_label(frame.span, format!("inside `{}`", frame.instance));
|
INVALID_ALIGNMENT,
|
||||||
}
|
ecx.stack().iter().find_map(|frame| frame.lint_root()).unwrap_or(CRATE_HIR_ID),
|
||||||
db
|
err.span,
|
||||||
},
|
err.error.to_string(),
|
||||||
),
|
|db| {
|
||||||
|
err.decorate(db, |_| {});
|
||||||
|
db
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
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
|
error: accessing memory with alignment 1, but alignment 4 is required
|
||||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
--> $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!
|
= 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: 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
|
= note: `#[deny(invalid_alignment)]` on by default
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
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:
|
Future incompatibility report: Future breakage diagnostic:
|
||||||
error: accessing memory with alignment 1, but alignment 4 is required
|
error: accessing memory with alignment 1, but alignment 4 is required
|
||||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
--> $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!
|
= 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: 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
|
= 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
|
error: accessing memory with alignment 1, but alignment 4 is required
|
||||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
--> $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!
|
= 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: 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
|
= note: `#[deny(invalid_alignment)]` on by default
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
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:
|
Future incompatibility report: Future breakage diagnostic:
|
||||||
error: accessing memory with alignment 1, but alignment 4 is required
|
error: accessing memory with alignment 1, but alignment 4 is required
|
||||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
--> $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!
|
= 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: 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
|
= note: `#[deny(invalid_alignment)]` on by default
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue