T0005 static-mut¶
Rule: No static mut.
| Code | T0005 (stable, never reused) |
| Id | static-mut |
| Category | state |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | deny |
global mutable state with no synchronisation; there is always a better owner |
| small-workspace | deny |
global mutable state with no synchronisation; there is always a better owner |
| medium | deny |
global mutable state with no synchronisation; there is always a better owner |
| big | deny |
global mutable state with no synchronisation; there is always a better owner |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Why¶
static mut is global mutable state with no synchronisation at all: every access is unsafe, and since edition 2024 taking a reference to one is an error. There is always a better owner.
How to fix¶
A counter or a flag is an atomic. Anything else gets one owner (see static-interior-mutability).
Configure¶
Allow one finding in the code with // spirit-level: allow(static-mut) <reason> (waivers); the code works there too, as in [lints.T0005].