Create rule S7413 Await should be used for awaitable returns in async blocks and functions (#4752)

* Create rule S7413

* Update rule.adoc

* Update metadata.json

* Update rule.adoc

* Update rule.adoc

* Update metadata.json

---------

Co-authored-by: sallaigy <sallaigy@users.noreply.github.com>
Co-authored-by: Gyula Sallai <gyula.sallai@sonarsource.com>
This commit is contained in:
github-actions[bot] 2025-03-19 14:09:13 +00:00 committed by GitHub
parent d17e141be3
commit cdb05a081b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,24 @@
{
"title": "Await should be used for awaitable returns in async blocks and functions",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Critical",
"ruleSpecification": "RSPEC-7413",
"sqKey": "S7413",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "HIGH"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,36 @@
== 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