Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
laralove143 opened this issue May 19, 2023 · 1 comment · Fixed by #10807
Closed

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

laralove143 opened this issue May 19, 2023 · 1 comment · Fixed by #10807
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@laralove143
Copy link

laralove143 commented May 19, 2023

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
@laralove143 laralove143 added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels May 19, 2023
@y21
Copy link
Member

y21 commented May 21, 2023

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants