@@ -9,7 +9,7 @@ use super::{
99use crate :: errors;
1010use crate :: maybe_recover_from_interpolated_ty_qpath;
1111use ast:: mut_visit:: { noop_visit_expr, MutVisitor } ;
12- use ast:: { Path , PathSegment } ;
12+ use ast:: { GenBlockKind , Path , PathSegment } ;
1313use core:: mem;
1414use rustc_ast:: ptr:: P ;
1515use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
@@ -1422,9 +1422,6 @@ impl<'a> Parser<'a> {
14221422 } else if this. is_try_block ( ) {
14231423 this. expect_keyword ( kw:: Try ) ?;
14241424 this. parse_try_block ( lo)
1425- } else if this. is_gen_block ( ) {
1426- this. expect_keyword ( kw:: Gen ) ?;
1427- this. parse_gen_block ( lo)
14281425 } else if this. eat_keyword ( kw:: Return ) {
14291426 this. parse_expr_return ( )
14301427 } else if this. eat_keyword ( kw:: Continue ) {
@@ -1446,12 +1443,14 @@ impl<'a> Parser<'a> {
14461443 if this. check_keyword ( kw:: Async ) {
14471444 if this. is_async_block ( ) {
14481445 // Check for `async {` and `async move {`.
1449- this. parse_async_block ( )
1446+ this. parse_gen_block ( )
14501447 } else {
14511448 this. parse_expr_closure ( )
14521449 }
14531450 } else if this. eat_keyword ( kw:: Await ) {
14541451 this. recover_incorrect_await_syntax ( lo, this. prev_token . span )
1452+ } else if this. token . uninterpolated_span ( ) . at_least_rust_2024 ( ) {
1453+ if this. is_gen_block ( ) { this. parse_gen_block ( ) } else { this. parse_expr_lit ( ) }
14551454 } else {
14561455 this. parse_expr_lit ( )
14571456 }
@@ -3043,14 +3042,6 @@ impl<'a> Parser<'a> {
30433042 }
30443043 }
30453044
3046- /// Parses a `gen {...}` expression (`gen` token already eaten).
3047- fn parse_gen_block ( & mut self , _span_lo : Span ) -> PResult < ' a , P < Expr > > {
3048- let ( _attrs, _body) = self . parse_inner_attrs_and_block ( ) ?;
3049-
3050- Err ( errors:: GenBlock { span : self . prev_token . span }
3051- . into_diagnostic ( & self . sess . span_diagnostic ) )
3052- }
3053-
30543045 fn is_do_catch_block ( & self ) -> bool {
30553046 self . token . is_keyword ( kw:: Do )
30563047 && self . is_keyword_ahead ( 1 , & [ kw:: Catch ] )
@@ -3077,13 +3068,18 @@ impl<'a> Parser<'a> {
30773068 && self . token . uninterpolated_span ( ) . at_least_rust_2024 ( )
30783069 }
30793070
3080- /// Parses an `async move? {...}` expression.
3081- fn parse_async_block ( & mut self ) -> PResult < ' a , P < Expr > > {
3071+ /// Parses an `async move? {...}` or `gen move? {...}` expression.
3072+ fn parse_gen_block ( & mut self ) -> PResult < ' a , P < Expr > > {
30823073 let lo = self . token . span ;
3083- self . expect_keyword ( kw:: Async ) ?;
3074+ let kind = if self . eat_keyword ( kw:: Async ) {
3075+ GenBlockKind :: Async
3076+ } else {
3077+ assert ! ( self . eat_keyword( kw:: Gen ) ) ;
3078+ GenBlockKind :: Gen
3079+ } ;
30843080 let capture_clause = self . parse_capture_clause ( ) ?;
30853081 let ( attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
3086- let kind = ExprKind :: Async ( capture_clause, body) ;
3082+ let kind = ExprKind :: Gen ( capture_clause, body, kind ) ;
30873083 Ok ( self . mk_expr_with_attrs ( lo. to ( self . prev_token . span ) , kind, attrs) )
30883084 }
30893085
@@ -3614,7 +3610,7 @@ impl MutVisitor for CondChecker<'_> {
36143610 | ExprKind :: Match ( _, _)
36153611 | ExprKind :: Closure ( _)
36163612 | ExprKind :: Block ( _, _)
3617- | ExprKind :: Async ( _, _)
3613+ | ExprKind :: Gen ( _ , _, _)
36183614 | ExprKind :: TryBlock ( _)
36193615 | ExprKind :: Underscore
36203616 | ExprKind :: Path ( _, _)
0 commit comments