Closed
Description
Summary
Looks like mutable self refs ignored in methods.
Discovered while working on rust-lang/rust#123188
Checked with clippy from playground 0.1.79 (2024-03-27 c9f8f34)
see also #9591
Lint Name
needless_pass_by_ref_mut
Reproducer
I tried this code:
#![warn(clippy::needless_pass_by_ref_mut)]
fn main() {}
struct Foo{
x: u8
}
impl Foo{
fn foo(&mut self)->u8{
self.x * 2
}
fn bar(&mut self, y: &mut u8)->u8{
self.x * *y
}
fn baz(&self, y: &mut u8)->u8{
self.x * *y
}
}
I expected to see this happen:
Should warn about unused &mut self in foo
and bar
Instead, this happened:
No warn for &mut self, only for y
:
warning: this argument is a mutable reference, but not used mutably
--> src/main.rs:14:26
|
14 | fn bar(&mut self, y: &mut u8)->u8{
| ^^^^^^^ help: consider changing to: `&u8`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::needless_pass_by_ref_mut)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: this argument is a mutable reference, but not used mutably
--> src/main.rs:18:22
|
18 | fn baz(&self, y: &mut u8)->u8{
| ^^^^^^^ help: consider changing to: `&u8`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
Version
No response