When an async block or function returns a value that is itself awaitable (like a Future
), it often indicates that the developer forgot
to await that value. This creates a nested future that must be awaited twice to get the actual result, which is rarely the intended behavior. Missing
an await can lead to unexpected behavior where async operations never actually execute, nested futures that require multiple awaits to resolve,
hard-to-debug problems, potential deadlocks, or blocking in async contexts.
Code examples
Noncompliant code example
async fn foo() {}
fn bar() {
let x = async {
foo() // Noncompliant: returns a future that needs to be awaited
};
}
Compliant solution
async fn foo() {}
fn bar() {
let x = async {
foo().await // Properly awaits the inner future
};
}