rust-lang / rust-lang/rust-clippy

False positive for `let_underscore_future`

Open
#9,932 17 comments 4 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

I just came across a case where I think the new let_underscore_future #9721 produces a false positive:

#[tokio::main]
async fn main() {
    let _ = tokio::spawn(async {
        println!("spawned")
    });
}

Playground

In this case the returned JoinHandle is a future, but it doesn't have to be awaited to make the provided future start execution.

Reproducer

I tried this code:

#[tokio::main]
async fn main() {
    let _ = tokio::spawn(async {
        println!("spawned")
    });
}

I expected to see this happen:

There should be no clippy warnings.

Instead, this happened:

warning: non-binding `let` on a future
 --> src/main.rs:3:5
  |
3 | /     let _ = tokio::spawn(async {
4 | |         println!("spawned")
5 | |     });
  | |_______^

Version
1.67.0-nightly

(2022-11-22 ff8c8dfbe66701531e3e)
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

Start with the implementation and tests for the let_underscore_future lint, then run the Tokio spawn reproducer from the issue. Done means this case produces no warning while the lint continues to identify non-binding lets on futures that should be awaited.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.