Skip to content

Commit 111f7ad

Browse files
Add UI test for needless_pass_by_ref_mut
1 parent 1d8e20a commit 111f7ad

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/ui/needless_pass_by_ref_mut.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![allow(unused)]
2+
3+
// Should only warn for `s`.
4+
fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
5+
*x += *b + s.len() as u32;
6+
}
7+
8+
struct Bar;
9+
10+
impl Bar {
11+
// Should not warn on `&mut self`.
12+
fn bar(&mut self) {}
13+
}
14+
15+
trait Babar {
16+
// Should not warn here since it's a trait method.
17+
fn method(arg: &mut u32);
18+
}
19+
20+
impl Babar for Bar {
21+
// Should not warn here since it's a trait method.
22+
fn method(a: &mut u32) {}
23+
}
24+
25+
fn main() {
26+
let mut u = 0;
27+
foo(&mut vec![0], &0, &mut u);
28+
println!("{u}");
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this argument is a mutable reference, but not used mutably
2+
--> $DIR/needless_pass_by_ref_mut.rs:4:11
3+
|
4+
LL | fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
5+
| ^^^^^^^^^^^^^ help: consider changing to &Vec<u32>
6+
|
7+
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)