Skip to content
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

Unhelpful error message when awaiting an async closure while forgetting the brackets #65923

Closed
gilescope opened this issue Oct 29, 2019 · 0 comments · Fixed by #66239
Closed
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. F-async_closure `#![feature(async_closure)]` P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gilescope
Copy link
Contributor

async fn _async_bar() -> u32 {
    let async_closure = async || {
       22_u32
    };
    
    async_closure.await
}

(Playground link

Obviously async_closure().await was what I should have written. It would be great if rustc suggested that maybe I shoudl try calling the closure rather than the error it currently offers:

error[E0277]: the trait bound `[closure@src/main.rs:6:25: 8:6]: std::future::Future` is not satisfied
   --> src/main.rs:10:5
    |
10  |     async_closure.await
    |     ^^^^^^^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `[closure@src/main.rs:6:25: 8:6]`
@Centril Centril added A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. F-async_closure `#![feature(async_closure)]` P-low Low priority requires-nightly This issue requires a nightly compiler in some way. 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 Oct 29, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 19, 2019
…, r=Centril

Suggest calling async closure when needed

When using an async closure as a value in a place that expects a future,
suggest calling the closure.

Fix rust-lang#65923.
Centril added a commit to Centril/rust that referenced this issue Nov 19, 2019
…, r=Centril

Suggest calling async closure when needed

When using an async closure as a value in a place that expects a future,
suggest calling the closure.

Fix rust-lang#65923.
@bors bors closed this as completed in 0487f0c Nov 19, 2019
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 AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. F-async_closure `#![feature(async_closure)]` P-low Low priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants