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 fns are actually impl Futures, you may consider this as the expected behavior (I don't agree, and impl Futures are already #[must_use]). If that is the case, there should be a way to make the compiler warn on unused .awaited values (when type of the .awaited value is not #[must_use]).
@rustbot modify labels: A-async-await A-lint -A-diagnostics
I tried this code:
I expected the compiler to warn about the unused return value in
without_warning(), but the compiler emitted two warnings inwith_warnings():Playground (tried using nightly 2020-10-18 b1496c6)
As the real return values of
async fns are actuallyimpl Futures, you may consider this as the expected behavior (I don't agree, andimpl Futures are already#[must_use]). If that is the case, there should be a way to make the compiler warn on unused.awaited values (when type of the.awaited value is not#[must_use]).@rustbot modify labels: A-async-await A-lint -A-diagnostics