-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
drop_copy should not trigger when drop is used in a match branch #9482
Comments
I don't think this use of |
That's a fair point. See below for a solution if we go in that direction.
This hurts readability: match x with {
A => { // 3 lines
foo();
}
B => { // 3 lines
let _ = foo();
}
C => drop(foo()),
} If the problem is that clippy wants to argue that drop should only be used for dropping and not for the additional type conversion it provides, then one solution I would see would be for the standard library to provide the following function like OCaml does: pub fn ignore<T>(_x: T) {} // This is the exact same implementation as drop. Until this function is provided, clippy should not complain about drop being used instead of ignore. Once ignore is provided, clippy should complain about the following:
Here is how I would compare both solutions:
|
Thanks for the examples. So it seems |
Sounds good to me. I also think that silencing the lint at top-level of match branches (i.e. |
[`drop_ref`]: don't lint idiomatic in match arm fixes #10122 As established in issue #9482, it is idiomatic to use a single `drop()` expression in a match arm to achieve a side-effect of a function while discarding its output. This should also apply to cases where the function returns a reference. The change to the lint's code was less than 1 line, because all the heavy lifting was done in PR #9491. --- changelog: FP: [`drop_ref`]: No longer lints idiomatic expression in `match` arms [#10142](#10142) <!-- changelog_checked -->
Summary
The lint description says:
This is wrong, drop can be used to forget that a function returns a non-unit type when the result value is sometimes useless.
Lint Name
drop_copy
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No error
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: