You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
structThingy{foo:Option<(u32,u32)>,}letmut thingy = Thingy{foo:None};
thingy.foo = Some((0,1));// This operation is effectively useless (no side-effects etc.)
thingy.foo.unwrap().1 = 2;// What intuitively we'd expected to passassert_eq!(thingy.foo.unwrap().1,2);
The lint is clearly meant to trigger on the thingy.foo.unwrap().1 = 2; line and probably ought to suggest:
Could be written as:
thingy.foo.as_mut().unwrap().1 = 2;
Though the exact details of the suggestion would likely tie the lint to only working on replacing the innards of Options or similar.
The text was updated successfully, but these errors were encountered:
If the thing being unwrapped wasn't Copy then we'd get a use-after-move error anyway, so this only seems to apply in cases where the assignment is into an lvalue which was copied.
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.
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: