Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
meithecatte opened this issue Apr 24, 2025 · 1 comment
Open

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

meithecatte opened this issue Apr 24, 2025 · 1 comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@meithecatte
Copy link
Contributor

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

@meithecatte meithecatte added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 24, 2025
@meithecatte
Copy link
Contributor Author

@rustbot label +A-async-await

@rustbot rustbot added the A-async-await Area: Async & Await label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants