-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider
#[must_use]
annotation on async fn
as also affecting the…
… `Future::Output` No longer lint against `#[must_use] async fn foo()`. When encountering a statement that awaits on a `Future`, check if the `Future`'s parent item is annotated with `#[must_use]` and emit a lint if so. This effectively makes `must_use` an annotation on the `Future::Output` instead of only the `Future` itself. Fix #78149.
- Loading branch information
Showing
4 changed files
with
93 additions
and
43 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
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 |
---|---|---|
@@ -1,26 +1,55 @@ | ||
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 | ||
error: unused implementer of `Future` that must be used | ||
--> $DIR/unused-async.rs:31:5 | ||
| | ||
LL | foo(); | ||
| ^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-async.rs:2:9 | ||
| | ||
LL | #![deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: futures do nothing unless you `.await` or poll them | ||
|
||
error: unused return value of `foo` that must be used | ||
--> $DIR/unused-async.rs:31:5 | ||
| | ||
LL | foo(); | ||
| ^^^^^ | ||
|
||
error: unused awaited future returned by `foo` that must be used | ||
--> $DIR/unused-async.rs:33:5 | ||
| | ||
LL | foo().await; | ||
| ^^^^^^^^^^^ | ||
|
||
error: unused implementer of `Future` that must be used | ||
--> $DIR/unused-async.rs:34:5 | ||
| | ||
LL | bar(); | ||
| ^^^^^ | ||
| | ||
= note: futures do nothing unless you `.await` or poll them | ||
|
||
error: unused return value of `bar` that must be used | ||
--> $DIR/unused-async.rs:34:5 | ||
| | ||
LL | bar(); | ||
| ^^^^^ | ||
|
||
error: unused awaited future returned by `bar` that must be used | ||
--> $DIR/unused-async.rs:36:5 | ||
| | ||
LL | bar().await; | ||
| ^^^^^^^^^^^ | ||
|
||
error: unused implementer of `Future` that must be used | ||
--> $DIR/unused-async.rs:37:5 | ||
| | ||
LL | baz(); | ||
| ^^^^^ | ||
| | ||
= note: futures do nothing unless you `.await` or poll them | ||
|
||
error: aborting due to 7 previous errors | ||
|