A-lintgood first issue
仓库指标
- Star
- (10,406 star)
- PR 合并指标
- (平均合并 19天 22小时) (30 天内合并 113 个 PR)
描述
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, etc
It would be good to point people to the edition guide explanation and the higher level sync objects docs.