Skip to content

Poor suggestion for async || {} in place of async {} #140265

Open
@meithecatte

Description

@meithecatte

Code

fn takes_future(fut: impl Future<Output=()>) {}

fn main() {
    takes_future(async || {
        println!("hi!");
    })
}

Current output

error[E0277]: `{async closure@src/main.rs:4:18: 4:26}` is not a future
 --> src/main.rs:4:18
  |
4 |       takes_future(async || {
  |  _____------------_^
  | |     |
  | |     required by a bound introduced by this call
5 | |         println!("hi!");
6 | |     })
  | |_____^ `{async closure@src/main.rs:4:18: 4:26}` is not a future
  |
  = help: the trait `Future` is not implemented for `{async closure@src/main.rs:4:18: 4:26}`
note: required by a bound in `takes_future`
 --> src/main.rs:1:27
  |
1 | fn takes_future(fut: impl Future<Output=()>) {}
  |                           ^^^^^^^^^^^^^^^^^ required by this bound in `takes_future`
help: use parentheses to call this closure
  |
6 |     }())
  |      ++

Desired output

error[E0277]: `{async closure@src/main.rs:4:18: 4:26}` is not a future
 --> src/main.rs:4:18
  |
4 |       takes_future(async || {
  |  _____------------_^
  | |     |
  | |     required by a bound introduced by this call
5 | |         println!("hi!");
6 | |     })
  | |_____^ `{async closure@src/main.rs:4:18: 4:26}` is not a future
  |
  = help: the trait `Future` is not implemented for `{async closure@src/main.rs:4:18: 4:26}`
note: required by a bound in `takes_future`
 --> src/main.rs:1:27
  |
1 | fn takes_future(fut: impl Future<Output=()>) {}
  |                           ^^^^^^^^^^^^^^^^^ required by this bound in `takes_future`
help: use an async block instead
  |
4 |     takes_future(async || {
  |                        ---

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.88.0-nightly (df35ff6c3 2025-04-23)
binary: rustc
commit-hash: df35ff6c354f1f1fbf430b84e7dea37dfe997f34
commit-date: 2025-04-23
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions