Skip to content

Commit 81d57de

Browse files
committed
Update needless_borrow test output and expected fix
1 parent 46c3076 commit 81d57de

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

tests/ui/needless_borrow.fixed

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
// run-rustfix
22

3-
#![allow(clippy::needless_borrowed_reference)]
4-
5-
fn x(y: &i32) -> i32 {
6-
*y
7-
}
8-
93
#[warn(clippy::all, clippy::needless_borrow)]
104
#[allow(unused_variables)]
115
fn main() {
126
let a = 5;
13-
let b = x(&a);
14-
let c = x(&a);
7+
let _ = x(&a); // no warning
8+
let _ = x(&a); // warn
9+
10+
let mut b = 5;
11+
mut_ref(&mut b); // no warning
12+
mut_ref(&mut b); // warn
13+
1514
let s = &String::from("hi");
1615
let s_ident = f(&s); // should not error, because `&String` implements Copy, but `String` does not
1716
let g_val = g(&Vec::new()); // should not error, because `&Vec<T>` derefs to `&[T]`
@@ -29,6 +28,15 @@ fn main() {
2928
};
3029
}
3130

31+
#[allow(clippy::needless_borrowed_reference)]
32+
fn x(y: &i32) -> i32 {
33+
*y
34+
}
35+
36+
fn mut_ref(y: &mut i32) {
37+
*y = 5;
38+
}
39+
3240
fn f<T: Copy>(y: &T) -> T {
3341
*y
3442
}

tests/ui/needless_borrow.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
2-
--> $DIR/needless_borrow.rs:14:15
2+
--> $DIR/needless_borrow.rs:8:15
33
|
4-
LL | let c = x(&&a);
4+
LL | let _ = x(&&a); // warn
55
| ^^^ help: change this to: `&a`
66
|
77
= note: `-D clippy::needless-borrow` implied by `-D warnings`
88

9+
error: this expression borrows a reference (`&mut i32`) that is immediately dereferenced by the compiler
10+
--> $DIR/needless_borrow.rs:12:13
11+
|
12+
LL | mut_ref(&mut &mut b); // warn
13+
| ^^^^^^^^^^^ help: change this to: `&mut b`
14+
915
error: this expression borrows a reference (`&i32`) that is immediately dereferenced by the compiler
10-
--> $DIR/needless_borrow.rs:27:15
16+
--> $DIR/needless_borrow.rs:26:15
1117
|
1218
LL | 46 => &&a,
1319
| ^^^ help: change this to: `&a`
1420

15-
error: aborting due to 2 previous errors
21+
error: aborting due to 3 previous errors
1622

0 commit comments

Comments
 (0)