Closed

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
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Attributes (`#[…]`, `#![…]`)Area: Lints (warnings about flaws in source code) such as unused_mut.Async-await issues that are part of the "polish" areaAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done