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

Comments

@gilescope
Copy link
Contributor

@gilescope gilescope commented Oct 29, 2019

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]`
estebank added a commit to estebank/rust that referenced this issue Nov 9, 2019
When using an async closure as a value in a place that expects a future,
suggest calling the closure.

Fix rust-lang#65923.
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.
bors added a commit that referenced this issue Nov 19, 2019
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 #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 in 0487f0c Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.