Skip to content

False positive clippy::redundant_closure_call when using async closures as async try block #16232

@StackOverflowExcept1on

Description

@StackOverflowExcept1on

Summary

Here's an example where you might want this (though this is a synchronous context):
https://github.com/dtolnay/sha1dir/blob/8c8946dec556bd26fab88d67662a7841b573bef4/src/main.rs#L146

Lint Name

clippy::redundant_closure_call

Reproducer

I tried this code:

#[tokio::main]
async fn main() {
    (async || -> Result<(), &'static str> { Ok(()) })()
        .await
        .unwrap();
}

I saw this happen:

    Checking playground v0.0.1 (/playground)
warning: try not to call a closure in the expression where it is declared
 --> src/main.rs:3:5
  |
3 |     (async || -> Result<(), &'static str> { Ok(()) })()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try doing something like: `async { Ok(()) }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#redundant_closure_call
  = note: `#[warn(clippy::redundant_closure_call)]` on by default

warning: `playground` (bin "playground") generated 1 warning (run `cargo clippy --fix --bin "playground" -p playground` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.65s

I expected to see this happen: this is valid code and it doesn't cause any problems since you just want to make an asynchronous try block.

Version

rustc 1.92.0-nightly (f04e3dfc8 2025-10-19)
binary: rustc
commit-hash: f04e3dfc87d7e2b6ad53e7a52253812cd62eba50
commit-date: 2025-10-19
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.3

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions