-
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
Unecessary mut
reference in parameter
#8863
Comments
I wonder if this could be also made into a separate lint where ownership is passed when a Basically, warning when your fn is taking more than it needs. I like it! |
Is this already covered by |
Good point. Maybe instead of |
Referencing the pass_by_value PR in case someone wants to look at it for inspiration: #1556 |
I'll take a look. |
I'm done with the implementation. I'll open a draft PR after the cleanup but I'll need people to test it so I can add more cases into the UI test. |
I opened the draft here. Please test it so we can uncover cases I didn't think about. Thanks in advance! :) |
What it does
It warns against using
&mut
in an parameter where&
would suffice.Lint Name
unnecessary-mut-ref
Category
suspicious
Advantage
Less
mut
means less fights with the borrow checker. It can also lead to more opportunities for parallelization.This lint could also catch bugs where the user intended to mutate an argument but forgot too.
Drawbacks
A user may want to create an API where they reserve the right to mutate an argument, but does not do so yet.
We should not warn when implementing a
trait
.Example
Could be written as:
The text was updated successfully, but these errors were encountered: