@@ -1520,22 +1520,20 @@ impl<'a> Parser<'a> {
1520
1520
Ok ( this. mk_expr ( this. prev_token . span , ExprKind :: Underscore ) )
1521
1521
} else if this. token_uninterpolated_span ( ) . at_least_rust_2018 ( ) {
1522
1522
// `Span::at_least_rust_2018()` is somewhat expensive; don't get it repeatedly.
1523
+ let at_async = this. check_keyword ( exp ! ( Async ) ) ;
1524
+ // check for `gen {}` and `gen move {}`
1525
+ // or `async gen {}` and `async gen move {}`
1526
+ // FIXME: (async) gen closures aren't yet parsed.
1527
+ // FIXME(gen_blocks): Parse `gen async` and suggest swap
1523
1528
if this. token_uninterpolated_span ( ) . at_least_rust_2024 ( )
1524
- // check for `gen {}` and `gen move {}`
1525
- // or `async gen {}` and `async gen move {}`
1526
- && ( this. is_gen_block ( kw:: Gen , 0 )
1527
- || ( this. check_keyword ( exp ! ( Async ) ) && this. is_gen_block ( kw:: Gen , 1 ) ) )
1529
+ && this. is_gen_block ( kw:: Gen , at_async as usize )
1528
1530
{
1529
- // FIXME: (async) gen closures aren't yet parsed.
1530
1531
this. parse_gen_block ( )
1531
- } else if this. check_keyword ( exp ! ( Async ) ) {
1532
- // FIXME(gen_blocks): Parse `gen async` and suggest swap
1533
- if this. is_gen_block ( kw:: Async , 0 ) {
1534
- // Check for `async {` and `async move {`,
1535
- this. parse_gen_block ( )
1536
- } else {
1537
- this. parse_expr_closure ( )
1538
- }
1532
+ // Check for `async {` and `async move {`,
1533
+ } else if this. is_gen_block ( kw:: Async , 0 ) {
1534
+ this. parse_gen_block ( )
1535
+ } else if at_async {
1536
+ this. parse_expr_closure ( )
1539
1537
} else if this. eat_keyword_noexpect ( kw:: Await ) {
1540
1538
this. recover_incorrect_await_syntax ( lo)
1541
1539
} else {
@@ -2407,6 +2405,14 @@ impl<'a> Parser<'a> {
2407
2405
None
2408
2406
} ;
2409
2407
2408
+ if let ClosureBinder :: NotPresent = binder
2409
+ && coroutine_kind. is_some ( )
2410
+ {
2411
+ // couroutine closures and generators can have the same qualifiers, so we might end up
2412
+ // in here if there is a missing `|` but also no `{`. Adjust the expectations in that case.
2413
+ self . expected_token_types . insert ( TokenType :: OpenBrace ) ;
2414
+ }
2415
+
2410
2416
let capture_clause = self . parse_capture_clause ( ) ?;
2411
2417
let ( fn_decl, fn_arg_span) = self . parse_fn_block_decl ( ) ?;
2412
2418
let decl_hi = self . prev_token . span ;
0 commit comments