Closed
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
}