Skip to content

Fix points at nonexisting .await #113263

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,14 +1666,8 @@ impl<'a> Parser<'a> {
self.recover_await_prefix(await_sp)?
};
let sp = self.error_on_incorrect_await(lo, hi, &expr, is_question);
let kind = match expr.kind {
// Avoid knock-down errors as we don't know whether to interpret this as `foo().await?`
// or `foo()?.await` (the very reason we went with postfix syntax 😅).
ExprKind::Try(_) => ExprKind::Err,
_ => ExprKind::Await(expr, await_sp),
};
let expr = self.mk_expr(lo.to(sp), kind);
self.maybe_recover_from_bad_qpath(expr)

Ok(self.mk_expr(sp, ExprKind::Err))
}

fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/parser/bad-await-body.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
await{}()
//~^ ERROR: cannot find struct, variant or union type `await` in this scope
}
9 changes: 9 additions & 0 deletions tests/ui/parser/bad-await-body.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0422]: cannot find struct, variant or union type `await` in this scope
--> $DIR/bad-await-body.rs:2:5
|
LL | await{}()
| ^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0422`.