Skip to content

unused_async not triggering when function only uses .await in an async block #10800

@laralove143

Description

@laralove143

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 thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions