-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Provide suggestion when creating static mut of type with internal mutability #151131
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.L-static_mut_refsLint: static_mut_refsLint: static_mut_refsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.L-static_mut_refsLint: static_mut_refsLint: static_mut_refsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Code
Current output
Desired output
Rationale and extra context
It is not necessarily obvious that
static mutshouldn't be used and what to use instead, but more importantly, when the user is already using a type that doesn't need to bemut, they might not immediately notice.This has been spotted in the wild: https://aus.social/@jpm/115891840629307599
Other cases
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=4434a1c05350f44776fcb9dfb7cb70c3
Lint doesn't trigger for
Rust Version
Anything else?
The documentation https://doc.rust-lang.org/edition-guide/rust-2024/static-mut-references.html#mutex-or-rwlock already mentions:
But we should provide suggestions for every case mentioned in that document. I notice that the lint doesn't trigger for
static mut COUNTER: u64 = 0;, which should suggest using atomics.