Skip to content

Unhelpful span in async type inference error #62382

Description

@Aaron1011

The following snippet (playground):

#![feature(async_await)]

use std::future::Future;

fn get_future() -> impl Future<Output = ()> {
    panic!()
}

async fn foo() {
    let a;
    get_future().await;
}

fn main() {}

Gives the following error message:

error[E0698]: type inside `async` object must be known in this context
  --> infer_error.rs:11:5
   |
11 |     get_future().await;
   |     ^^^^^^^^^^^^^^^^^^ cannot infer type
   |
note: the type is part of the `async` object because of this `await`
  --> infer_error.rs:11:5
   |
11 |     get_future().await;
   |     ^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

This error is due to the unknown type of a. However, nothing in the span indicates that this is the case, making it extremely unclear what the proper fix is.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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