@@ -1520,22 +1520,20 @@ impl<'a> Parser<'a> {
15201520 Ok ( this. mk_expr ( this. prev_token . span , ExprKind :: Underscore ) )
15211521 } else if this. token_uninterpolated_span ( ) . at_least_rust_2018 ( ) {
15221522 // `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
15231528 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 )
15281530 {
1529- // FIXME: (async) gen closures aren't yet parsed.
15301531 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 ( )
15391537 } else if this. eat_keyword_noexpect ( kw:: Await ) {
15401538 this. recover_incorrect_await_syntax ( lo)
15411539 } else {
@@ -2407,6 +2405,14 @@ impl<'a> Parser<'a> {
24072405 None
24082406 } ;
24092407
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+
24102416 let capture_clause = self . parse_capture_clause ( ) ?;
24112417 let ( fn_decl, fn_arg_span) = self . parse_fn_block_decl ( ) ?;
24122418 let decl_hi = self . prev_token . span ;
0 commit comments