Skip to content

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

Closed
@gilescope

Description

@gilescope
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]`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-async-closures`async || {}`A-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions