rust-lang / rust-lang/rust-clippy

Clippy `redundant_closure_call` suggests `async async move`

Open
#11,707 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Using tokio::task::Builder to create tasks, Clippy offers a redundant_closure_call warning and suggests I utilize async async move.

Reproducer

I tried this code:

fn demo(runtime: &tokio::runtime::Handle) {
    tokio::task::Builder::default().name("Foo").spawn_on((|| async move {
    })(), runtime).unwrap();
}

fn main() {
    let runtime = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build().unwrap();

    demo(runtime.handle());
}
[dependencies]
tokio = { version = "1.32.0", features = ["full", "rt-multi-thread", "tracing"] }

I expected to see this happen: Clippy offers something that can compile, or is OK with this approach.

Instead, this happened:

warning: try not to call a closure in the expression where it is declared
 --> src/main.rs:3:58
  |
3 |       tokio::task::Builder::default().name("Foo").spawn_on((|| async move {
  |  __________________________________________________________^
4 | |     })(), &runtime).unwrap();
  | |________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
  = note: `#[warn(clippy::redundant_closure_call)]` on by default
help: try doing something like
  |
3 ~     tokio::task::Builder::default().name("Foo").spawn_on(async async move {
4 ~     }, &runtime).unwrap();
  |
Version
rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the Rust reproducer as the first test case, then inspect the redundant_closure_call lint's diagnostic generation. Confirm that the suggested replacement compiles for the Tokio task expression, and cover the regression in Clippy's relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.