Skip to content

False positive redundant_async_block when making a Future from an IntoFuture #11959

@connec

Description

@connec

Summary

I'm working with a type that implements IntoFuture but not Future. I want to use tokio::task::spawn which only accepts a Future (not IntoFuture).

I wanted to avoid importing IntoFuture so I attempted tokio::task::spawn(async { fut.await }). This calls IntoFuture via the desugaring of .await, but clippy thinks it is redundant. Applying the suggestion to remove the async { ... } leads to non-compiling code.

Lint Name

redundant_async_block

Reproducer

I tried this code:

use std::future::{ready, IntoFuture, Ready}; struct Server; impl IntoFuture for Server { type Output = (); type IntoFuture = Ready<()>; fn into_future(self) -> Self::IntoFuture { ready(()) } } fn main() { tokio::task::spawn(async { Server.await }); }

I saw this happen:

warning: this async expression only awaits a single future --> src/main.rs:15:24 | 15 | tokio::task::spawn(async { Server.await }); | ^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `Server` | 

I expected to see this happen:

<no output> 

Note that applying clippy's suggestion leads to a compilation error.

Version

rustc 1.74.1 (a28077b28 2023-12-04) binary: rustc commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1 commit-date: 2023-12-04 host: aarch64-apple-darwin release: 1.74.1 LLVM version: 17.0.4 

Additional Labels

@rustbot label I-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions