Skip to content

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

Closed
@Aaron1011

Description

@Aaron1011
Member

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.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
C-bugCategory: This is a bug.
D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
on Jun 25, 2020
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jun 26, 2020
added
AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
on Jun 30, 2020
added a commit that references this issue on May 17, 2021
500503b
added 2 commits that reference this issue on May 18, 2021

Rollup merge of rust-lang#85393 - Aaron1011:async-type-err, r=varkor

f89345d

Rollup merge of rust-lang#85393 - Aaron1011:async-type-err, r=varkor

5f544bc
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 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

      Participants

      @nikomatsakis@Aaron1011@JohnTitor

      Issue actions

        Type error in `async` function causes spurious "type must be known in this context" error · Issue #73741 · rust-lang/rust