rust-lang / rust-lang/rust-clippy

`redundant_async_block` not catching uses with nontrivial futures

Open
#12,732 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

The redundant_async_block lint fails to trigger on uses of async { EXPRESSION.await } for seemingly any EXPRESSION other than a single variable.

Lint Name

redundant_async_block

Reproducer

I tried this code:

use std::future::ready;

pub fn foo() {
    tokio::spawn(async { ready(42).await });
}

I expected to see this happen: clippy should have warned about the redundant async block and recommended just writing tokio::spawn(ready(42)) instead.

Instead, this happened: no warnings

Version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-apple-darwin
release: 1.77.2
LLVM version: 17.0.6

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 redundant_async_block lint and reproduce the issue using the ready(42).await example. Trace how the lint handles async blocks whose awaited expression is not a single variable. Done means Clippy warns on this case and recommends tokio::spawn(ready(42)) without regressing existing behavior.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.