-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.AsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

Description
I tried this code:
#[must_use]
async fn foo() -> i32 {
std::future::pending().await
}
pub fn with_warnings() {
foo();
}
pub async fn without_warning() {
foo().await;
}
I expected the compiler to warn about the unused return value in without_warning()
, but the compiler emitted two warnings in with_warnings()
:
warning: unused implementer of `Future` that must be used
--> src/lib.rs:7:5
|
7 | foo();
| ^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: futures do nothing unless you `.await` or poll them
warning: unused return value of `foo` that must be used
--> src/lib.rs:7:5
|
7 | foo();
| ^^^^^^
Playground (tried using nightly 2020-10-18 b1496c6)
As the real return values of async fn
s are actually impl Future
s, you may consider this as the expected behavior (I don't agree, and impl Future
s are already #[must_use]
). If that is the case, there should be a way to make the compiler warn on unused .await
ed values (when type of the .await
ed value is not #[must_use]
).
@rustbot modify labels: A-async-await A-lint -A-diagnostics
robjtede and jazeved0
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.AsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done