-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Lint - Pointless mutation #13977
Comments
Some extra thoughts: If the thing being unwrapped wasn't |
I think it's a valid case. |
If someone could guide me into how I might go about building such a lint (eg. pointing me at anything which might be similar) I'm prepared to have a go at a solution myself; though it'd be my first time in the clippy codebase. |
Perhaps it's rustc that should warn for code like this, instead of Clippy? |
I'd be quite content if it were |
What it does
The lint should detect situations in which newly created values are mutated and then immediately dropped during assignments.
Advantage
Would spot situations such as the example below and warn the user that it is not acting as the author intended.
Drawbacks
Deliberate discarding of values may end up being slightly less ergonomic in some corner cases.
Example
This example is possibly a bit wordy, but is a simplified example of something encountered during a code review at work:
The lint is clearly meant to trigger on the
thingy.foo.unwrap().1 = 2;
line and probably ought to suggest:Could be written as:
Though the exact details of the suggestion would likely tie the lint to only working on replacing the innards of
Option
s or similar.The text was updated successfully, but these errors were encountered: