-
Notifications
You must be signed in to change notification settings - Fork 2k
Deny static mut declarations entirely #12896
Copy link
Copy link
Open
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
The static_mut_refs rustc lint checks for shared or mutable references of mutable statics. This catches most incorrect uses, but doesn't necessarily accomplish the goal of moving the ecosystem away from static mut entirely.
The static_mut clippy lint will check for any declarations of mutable statics, and recommend using an immutable static with a type with interior mutability instead.
Advantage
Move the ecosystem away from static mut. May even catch some unsoundness issues.
Drawbacks
Churn
Example
static mut NUM: usize = 0;
static mut FOO: Thing = Thing::new();Could be written as:
static NUM: AtomicUsize = AtomicUsize::new(0);
static FOO: Mutex<Thing> = Mutex::new(Thing::new());
// Or RwLock, LazyLock, SyncUnsafeCell, etcIt would be good to point people to the edition guide explanation and the higher level sync objects docs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Type
Fields
Give feedbackNo fields configured for issues without a type.