rspec/rules/S7413/rust/rule.adoc

37 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
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
[source,rust,diff-id=1,diff-type=noncompliant]
----
async fn foo() {}
fn bar() {
let x = async {
foo() // Noncompliant: returns a future that needs to be awaited
};
}
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
async fn foo() {}
fn bar() {
let x = async {
foo().await // Properly awaits the inner future
};
}
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async