-
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
Option::as_mut
followed by Option::take
is a foot-gun
#13671
Comments
FWIW, this inspired by a real-world bug: firezone/firezone#7288 |
@rustbot claim |
Hi Thomas, thanks for reporting this! It turns out clippy already has a lint that checks for usages of the form I think we should remove the suggestions emitted by Should the lint be moved to the |
To be more general, if |
I think for
I think you are on the money there! I think |
What it does
Warns users that calling
take
on anOption
created byas_mut
does not clear the originalOption
.It is useless to
take
anOption
that is only holding a reference, one might as well pattern match on it directly.Advantage
It makes it clearer that the original option is not modified.
Drawbacks
No response
Example
"Calling
take
on anOption
with a reference does not clear the originalOption
. Removeas_mut
or pattern-match on the option directly if you did not intend to clear it."Could be written as:
The text was updated successfully, but these errors were encountered: