Skip to content

Type error in async function causes spurious "type must be known in this context" error #73741

Closed
@Aaron1011

Description

@Aaron1011

The following code:

async fn weird() {
    1 = 2;
    
    let mut loop_count = 0;
    async {}.await
}

fn main() {}

produces the following errors:

error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:2:7
  |
2 |     1 = 2;
  |     - ^
  |     |
  |     cannot assign to this expression

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:4:9
  |
4 |     let mut loop_count = 0;
  |         ^^^^^^^^^^^^^^ cannot infer type for type `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:5:5
  |
5 |     async {}.await
  |     ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

The "type inside async fn body must be known in this context" error is spurious, and disappears if the 1 = 2; line is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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