Skip to content

Commit 96b14e6

Browse files
committed
Make parser aware of await where macro calls are expected
This makes the parser to first check for '!' and see if it exists or not before parsing it as `await!`. This is done because a proposed new syntax for await is `expression.await` and hence await keyword can be used without `!`. It fixes #60653
1 parent 80e7cde commit 96b14e6

5 files changed

+8
-7
lines changed

src/libsyntax/parse/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,8 @@ impl<'a> Parser<'a> {
26282628
db.span_label(self.span, "expected expression");
26292629
db.note("variable declaration using `let` is a statement");
26302630
return Err(db);
2631-
} else if self.span.rust_2018() && self.eat_keyword(keywords::Await) {
2631+
} else if self.span.rust_2018() && self.eat_keyword(keywords::Await)
2632+
&& self.check(&token::Not) {
26322633
// FIXME: remove this branch when `await!` is no longer supported
26332634
// https://github.com/rust-lang/rust/issues/60610
26342635
self.expect(&token::Not)?;

src/test/ui/await-keyword/2018-edition-error-in-non-macro-position.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ macro_rules! await {
2323
}
2424

2525
fn main() {
26-
match await { await => () } //~ ERROR expected `!`, found `{`
26+
match await { await => () } //~ ERROR expected expression, found `{`
2727
}

src/test/ui/await-keyword/2018-edition-error-in-non-macro-position.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ help: you can escape reserved keywords to use them as identifiers
6868
LL | macro_rules! r#await {
6969
| ^^^^^^^
7070

71-
error: expected `!`, found `{`
71+
error: expected expression, found `{`
7272
--> $DIR/2018-edition-error-in-non-macro-position.rs:26:17
7373
|
7474
LL | match await { await => () }
75-
| ----- ^ expected `!`
75+
| ----- ^ expected expression
7676
| |
7777
| while parsing this match expression
7878

src/test/ui/await-keyword/2018-edition-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ use self::outer_mod::await::await; //~ ERROR expected identifier
1010
//~^ ERROR expected identifier, found reserved keyword `await`
1111

1212
fn main() {
13-
match await { await => () } //~ ERROR expected `!`, found `{`
13+
match await { await => () } //~ ERROR expected expression, found `{`
1414
}

src/test/ui/await-keyword/2018-edition-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ help: you can escape reserved keywords to use them as identifiers
3838
LL | use self::outer_mod::await::r#await;
3939
| ^^^^^^^
4040

41-
error: expected `!`, found `{`
41+
error: expected expression, found `{`
4242
--> $DIR/2018-edition-error.rs:13:17
4343
|
4444
LL | match await { await => () }
45-
| ----- ^ expected `!`
45+
| ----- ^ expected expression
4646
| |
4747
| while parsing this match expression
4848

0 commit comments

Comments
 (0)