-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Closed
Copy link
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
it seems the lint is simply checking for an occurrence of .await literal in the code, this is not always accurate, we can put an async block inside a sync function and use .await in the block, so making that function async is unnecessary but the lint still doesnt trigger
Lint Name
unused_async
Reproducer
playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c31e923630b481e7c9d6c40a610d84a2
#![deny(clippy::unused_async)]
#![allow(dead_code, unused_must_use, clippy::no_effect)]
// works fine
async fn async_block_no_await() {
async {
tokio::time::sleep(std::time::Duration::from_secs(1));
};
}
// false negative
async fn async_block_await() {
async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
};
}
// proof that it can be sync
fn async_block_await_sync() {
async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
};
}Version
even on playground
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't