Skip to content

unused_async doesn't trigger if the function is passed into another function #13466

Open
@junbl

Description

@junbl

Summary

If an async function (with no await statements) is passed into another function as an argument, it no longer triggers the unused_async lint.

Believe this is a relatively recent issue - came up now because I replaced our allows with expects, but we've had a good amount of these unused_asyncs for a while.

Side note - at first I thought this was because the function it was passed into required its argument to be an async function and unused_async was smart enough to detect that, but unfortunately not. That'd be a nice feature though!

Lint Name

unused_async

Reproducer

I tried this code:

#![deny(clippy::unused_async)]

pub async fn unused_async() {}

fn baz<F>(_: F) {}

fn main() {
    
    // suppresses unused_async
    baz(unused_async);
    
}

I expected to see this happen: unused_async triggers as there are no await statements.

Instead, this happened: unused_async does not trigger, and expect produces "unfulfilled lint".

Interestingly, this only happens when my async fn is passed into another function, not if you call a method on the async fn (even if it's the same function):

#![deny(clippy::unused_async)]

pub async fn unused_async() {}

trait Foo {
    fn bar(&self) {
        
    }
}
impl<F> Foo for F { }

fn main() {

    // does not suppress unused_async
    unused_async.bar();
    
    // suppresses unused_async
    Foo::bar(&unused_async);
}

playground

Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

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