-
Notifications
You must be signed in to change notification settings - Fork 2k
Unecessary mut reference in parameter #8863
Copy link
Copy link
Closed
Labels
A-lintArea: New lintsArea: New lints
Description
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
fn foo(&mut self, y: &mut i32) -> i32 {
self.x + *y
}Could be written as:
fn foo(&self, y: &i32) -> i32 {
self.x + *y
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints
Type
Fields
Give feedbackNo fields configured for issues without a type.