Skip to content

Commit 0b76479

Browse files
authored
Merge pull request #76 from dtolnay/mustuse
Add must_use to async trait methods
2 parents 600058f + a42fc09 commit 0b76479

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/expand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
7575
}
7676
let has_default = method.default.is_some();
7777
transform_sig(context, sig, has_self, has_default, is_local);
78+
method.attrs.push(parse_quote!(#[must_use]));
7879
}
7980
}
8081
}

tests/ui/must-use.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![deny(unused_must_use)]
2+
3+
use async_trait::async_trait;
4+
5+
#[async_trait]
6+
trait Interface {
7+
async fn f(&self);
8+
}
9+
10+
struct Thing;
11+
12+
#[async_trait]
13+
impl Interface for Thing {
14+
async fn f(&self) {}
15+
}
16+
17+
pub async fn f() {
18+
Thing.f();
19+
}
20+
21+
fn main() {}

tests/ui/must-use.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: unused return value of `Interface::f` that must be used
2+
--> $DIR/must-use.rs:18:5
3+
|
4+
18 | Thing.f();
5+
| ^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/must-use.rs:1:9
9+
|
10+
1 | #![deny(unused_must_use)]
11+
| ^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)