Skip to content

async/await errors should not discuss "yield statements" #51751

Closed
@sophiajt

Description

@sophiajt

Awesome to see async/await starting to light up. I poked around and hit a snag putting together a naive little example. Clearly, this example is probably missing a bit more to get it running, but I just wanted to point the error here doesn't quite help:

#![feature(arbitrary_self_types, async_await, await_macro, futures_api, pin)]

async fn inc(limit: i64) -> i64 {
    limit + 1
}

fn main() {
    let result = inc(10000);
    let finished = await!(result);
}

For the above, you get:

error[E0627]: yield statement outside of generator literal
  --> src/main.rs:22:20
   |
22 |     let finished = await!(result);
   |                    ^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Which immediately makes you wonder "what yield statement?" I suspect one of the first things people will want to try is awaiting an async function, so we might want to gently point them in the right direction.

cc @estebank @cramertj

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaP-mediumMedium priorityT-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