-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI test for
needless_pass_by_ref_mut
- Loading branch information
1 parent
1d8e20a
commit 111f7ad
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![allow(unused)] | ||
|
||
// Should only warn for `s`. | ||
fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) { | ||
*x += *b + s.len() as u32; | ||
} | ||
|
||
struct Bar; | ||
|
||
impl Bar { | ||
// Should not warn on `&mut self`. | ||
fn bar(&mut self) {} | ||
} | ||
|
||
trait Babar { | ||
// Should not warn here since it's a trait method. | ||
fn method(arg: &mut u32); | ||
} | ||
|
||
impl Babar for Bar { | ||
// Should not warn here since it's a trait method. | ||
fn method(a: &mut u32) {} | ||
} | ||
|
||
fn main() { | ||
let mut u = 0; | ||
foo(&mut vec![0], &0, &mut u); | ||
println!("{u}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: this argument is a mutable reference, but not used mutably | ||
--> $DIR/needless_pass_by_ref_mut.rs:4:11 | ||
| | ||
LL | fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) { | ||
| ^^^^^^^^^^^^^ help: consider changing to &Vec<u32> | ||
| | ||
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|