Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, r=compiler-errors
make writes_through_immutable_pointer a hard error This turns the lint added in https://github.com/rust-lang/rust/pull/118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in https://github.com/rust-lang/rust/pull/117905. Still, let's do a crater run just to be sure. Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc ``@rust-lang/lang`` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of https://github.com/rust-lang/rust/pull/129195 which is already nominated for discussion.
This commit is contained in:
commit
05b8bcc662
7 changed files with 23 additions and 102 deletions
|
@ -142,7 +142,6 @@ declare_lint_pass! {
|
|||
USELESS_DEPRECATED,
|
||||
WARNINGS,
|
||||
WASM_C_ABI,
|
||||
WRITES_THROUGH_IMMUTABLE_POINTER,
|
||||
// tidy-alphabetical-end
|
||||
]
|
||||
}
|
||||
|
@ -4696,40 +4695,6 @@ declare_lint! {
|
|||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `writes_through_immutable_pointer` lint detects writes through pointers derived from
|
||||
/// shared references.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// #![feature(const_mut_refs)]
|
||||
/// const WRITE_AFTER_CAST: () = unsafe {
|
||||
/// let mut x = 0;
|
||||
/// let ptr = &x as *const i32 as *mut i32;
|
||||
/// *ptr = 0;
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// Shared references are immutable (when there is no `UnsafeCell` involved),
|
||||
/// and writing through them or through pointers derived from them is Undefined Behavior.
|
||||
/// The compiler recently learned to detect such Undefined Behavior during compile-time
|
||||
/// evaluation, and in the future this will raise a hard error.
|
||||
///
|
||||
/// [future-incompatible]: ../index.md#future-incompatible-lints
|
||||
pub WRITES_THROUGH_IMMUTABLE_POINTER,
|
||||
Warn,
|
||||
"shared references are immutable, and pointers derived from them must not be written to",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
|
||||
reference: "issue #X <https://github.com/rust-lang/rust/issues/X>",
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `private_macro_use` lint detects private macros that are imported
|
||||
/// with `#[macro_use]`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue