From 9cae051d23927118fe2e069f33bada070f6ac603 Mon Sep 17 00:00:00 2001 From: Alef Date: Mon, 10 Jul 2023 20:18:17 -0300 Subject: [PATCH 1/2] add test --- tests/ui/parser/bad-await-body.rs | 4 ++++ tests/ui/parser/bad-await-body.stderr | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/ui/parser/bad-await-body.rs create mode 100644 tests/ui/parser/bad-await-body.stderr 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`. From 155887621e4aa47f096ca75167349835e509454d Mon Sep 17 00:00:00 2001 From: Alef Date: Mon, 10 Jul 2023 22:31:04 -0300 Subject: [PATCH 2/2] always return ExprKind::Err --- compiler/rustc_parse/src/parser/diagnostics.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) 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)> {