Skip to content

Commit 1228868

Browse files
committed
Test for #[must_use] on traits
1 parent cb5520b commit 1228868

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/test/ui/lint/must_use-trait.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![deny(unused_must_use)]
2+
3+
#[must_use]
4+
trait Critical {}
5+
6+
trait NotSoCritical {}
7+
8+
trait DecidedlyUnimportant {}
9+
10+
struct Anon;
11+
12+
impl Critical for Anon {}
13+
impl NotSoCritical for Anon {}
14+
impl DecidedlyUnimportant for Anon {}
15+
16+
fn get_critical() -> impl NotSoCritical + Critical + DecidedlyUnimportant {
17+
Anon {}
18+
}
19+
20+
fn main() {
21+
get_critical(); //~ ERROR unused implementer of `Critical` that must be used
22+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused implementer of `Critical` that must be used
2+
--> $DIR/must_use-trait.rs:21:5
3+
|
4+
LL | get_critical(); //~ ERROR unused implementer of `Critical` that must be used
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/must_use-trait.rs:1:9
9+
|
10+
LL | #![deny(unused_must_use)]
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)