Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aaron1011 opened this issue Jun 25, 2020 · 0 comments · Fixed by #85393
Closed
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Jun 25, 2020

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.

@Aaron1011 Aaron1011 added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. A-async-await Area: Async & Await D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Jun 25, 2020
@JohnTitor JohnTitor added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 26, 2020
@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Jun 30, 2020
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 18, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 18, 2021
@bors bors closed this as completed in 500503b May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants