forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#89610 - guswynn:must_use_future, r=wesleywiser
warn on must_use use on async fn's As referenced in rust-lang#78149 This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// edition:2018 | ||
// run-pass | ||
#![allow(dead_code)] | ||
|
||
#[must_use] | ||
//~^ WARNING `must_use` | ||
async fn test() -> i32 { | ||
1 | ||
} | ||
|
||
|
||
struct Wowee {} | ||
|
||
impl Wowee { | ||
#[must_use] | ||
//~^ WARNING `must_use` | ||
async fn test_method() -> i32 { | ||
1 | ||
} | ||
} | ||
|
||
/* FIXME(guswynn) update this test when async-fn-in-traits works | ||
trait Doer { | ||
#[must_use] | ||
async fn test_trait_method() -> i32; | ||
WARNING must_use | ||
async fn test_other_trait() -> i32; | ||
} | ||
impl Doer for Wowee { | ||
async fn test_trait_method() -> i32 { | ||
1 | ||
} | ||
#[must_use] | ||
async fn test_other_trait() -> i32 { | ||
WARNING must_use | ||
1 | ||
} | ||
} | ||
*/ | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
warning: `must_use` attribute on `async` functions applies to the anonymous `Future` returned by the function, not the value within | ||
--> $DIR/unused-async.rs:5:1 | ||
| | ||
LL | #[must_use] | ||
| ^^^^^^^^^^^ | ||
LL | | ||
LL | / async fn test() -> i32 { | ||
LL | | 1 | ||
LL | | } | ||
| |_- this attribute does nothing, the `Future`s returned by async functions are already `must_use` | ||
| | ||
= note: `#[warn(unused_attributes)]` on by default | ||
|
||
warning: `must_use` attribute on `async` functions applies to the anonymous `Future` returned by the function, not the value within | ||
--> $DIR/unused-async.rs:15:5 | ||
| | ||
LL | #[must_use] | ||
| ^^^^^^^^^^^ | ||
LL | | ||
LL | / async fn test_method() -> i32 { | ||
LL | | 1 | ||
LL | | } | ||
| |_____- this attribute does nothing, the `Future`s returned by async functions are already `must_use` | ||
|
||
warning: 2 warnings emitted | ||
|