Skip to content

Add must_use to async trait methods #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
}
let has_default = method.default.is_some();
transform_sig(context, sig, has_self, has_default, is_local);
method.attrs.push(parse_quote!(#[must_use]));
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/must-use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![deny(unused_must_use)]

use async_trait::async_trait;

#[async_trait]
trait Interface {
async fn f(&self);
}

struct Thing;

#[async_trait]
impl Interface for Thing {
async fn f(&self) {}
}

pub async fn f() {
Thing.f();
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/must-use.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: unused return value of `Interface::f` that must be used
--> $DIR/must-use.rs:18:5
|
18 | Thing.f();
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/must-use.rs:1:9
|
1 | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^