Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors
Disallow hidden references to mutable static Closes #123060 Tracking: - https://github.com/rust-lang/rust/issues/123758
This commit is contained in:
commit
5ba6db1b64
124 changed files with 1006 additions and 877 deletions
|
@ -99,7 +99,6 @@ declare_lint_pass! {
|
|||
SINGLE_USE_LIFETIMES,
|
||||
SOFT_UNSTABLE,
|
||||
STABLE_FEATURES,
|
||||
STATIC_MUT_REFS,
|
||||
TEST_UNSTABLE_LINT,
|
||||
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
|
||||
TRIVIAL_CASTS,
|
||||
|
@ -1927,57 +1926,6 @@ declare_lint! {
|
|||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `static_mut_refs` lint checks for shared or mutable references
|
||||
/// of mutable static inside `unsafe` blocks and `unsafe` functions.
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,edition2021
|
||||
/// fn main() {
|
||||
/// static mut X: i32 = 23;
|
||||
/// static mut Y: i32 = 24;
|
||||
///
|
||||
/// unsafe {
|
||||
/// let y = &X;
|
||||
/// let ref x = X;
|
||||
/// let (x, y) = (&X, &Y);
|
||||
/// foo(&X);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// unsafe fn _foo() {
|
||||
/// static mut X: i32 = 23;
|
||||
/// static mut Y: i32 = 24;
|
||||
///
|
||||
/// let y = &X;
|
||||
/// let ref x = X;
|
||||
/// let (x, y) = (&X, &Y);
|
||||
/// foo(&X);
|
||||
/// }
|
||||
///
|
||||
/// fn foo<'a>(_x: &'a i32) {}
|
||||
/// ```
|
||||
///
|
||||
/// {{produces}}
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// Shared or mutable references of mutable static are almost always a mistake and
|
||||
/// can lead to undefined behavior and various other problems in your code.
|
||||
///
|
||||
/// This lint is "warn" by default on editions up to 2021, in 2024 there is
|
||||
/// a hard error instead.
|
||||
pub STATIC_MUT_REFS,
|
||||
Warn,
|
||||
"shared references or mutable references of mutable static is discouraged",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #114447 <https://github.com/rust-lang/rust/issues/114447>",
|
||||
explain_reason: false,
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `absolute_paths_not_starting_with_crate` lint detects fully
|
||||
/// qualified paths that start with a module name instead of `crate`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue