Skip to content

Commit 4f8b259

Browse files
Add test for unused_borrows lint
1 parent 222fb63 commit 4f8b259

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/test/ui/lint/unused-borrows.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![deny(unused_must_use)]
2+
3+
fn foo(_: i32) -> bool { todo!() }
4+
5+
fn bar() -> &'static i32 {
6+
&42;
7+
//~^ unused
8+
9+
&mut foo(42);
10+
//~^ unused
11+
12+
&&42;
13+
//~^ unused
14+
15+
&&mut 42;
16+
//~^ unused
17+
18+
&mut &42;
19+
//~^ unused
20+
21+
let _result = foo(4)
22+
&& foo(2); // Misplaced semi-colon (perhaps due to reordering of lines)
23+
&& foo(42);
24+
//~^ unused
25+
26+
let _ = &42; // ok
27+
28+
&42 // ok
29+
}
30+
31+
fn main() {
32+
let _ = bar();
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error: unused borrow that must be used
2+
--> $DIR/unused-borrows.rs:6:5
3+
|
4+
LL | &42;
5+
| ^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-borrows.rs:1:9
9+
|
10+
LL | #![deny(unused_must_use)]
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: unused borrow that must be used
14+
--> $DIR/unused-borrows.rs:9:5
15+
|
16+
LL | &mut foo(42);
17+
| ^^^^^^^^^^^^
18+
19+
error: unused borrow that must be used
20+
--> $DIR/unused-borrows.rs:12:5
21+
|
22+
LL | &&42;
23+
| ^^^^
24+
25+
error: unused borrow that must be used
26+
--> $DIR/unused-borrows.rs:15:5
27+
|
28+
LL | &&mut 42;
29+
| ^^^^^^^^
30+
31+
error: unused borrow that must be used
32+
--> $DIR/unused-borrows.rs:18:5
33+
|
34+
LL | &mut &42;
35+
| ^^^^^^^^
36+
37+
error: unused borrow that must be used
38+
--> $DIR/unused-borrows.rs:23:9
39+
|
40+
LL | && foo(42);
41+
| ^^^^^^^^^^
42+
43+
error: aborting due to 6 previous errors
44+

0 commit comments

Comments
 (0)