diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 0ce6a570d258d..79bfa35de623c 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -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, bool)> { diff --git a/tests/ui/parser/bad-await-body.rs b/tests/ui/parser/bad-await-body.rs new file mode 100644 index 0000000000000..7517c4ff547de --- /dev/null +++ b/tests/ui/parser/bad-await-body.rs @@ -0,0 +1,4 @@ +fn main() { + await{}() + //~^ ERROR: cannot find struct, variant or union type `await` in this scope +} diff --git a/tests/ui/parser/bad-await-body.stderr b/tests/ui/parser/bad-await-body.stderr new file mode 100644 index 0000000000000..ab840acb063cf --- /dev/null +++ b/tests/ui/parser/bad-await-body.stderr @@ -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`.