@@ -9,7 +9,7 @@ use super::{
9
9
use crate :: errors;
10
10
use crate :: maybe_recover_from_interpolated_ty_qpath;
11
11
use ast:: mut_visit:: { noop_visit_expr, MutVisitor } ;
12
- use ast:: { Path , PathSegment } ;
12
+ use ast:: { GenBlockKind , Path , PathSegment } ;
13
13
use core:: mem;
14
14
use rustc_ast:: ptr:: P ;
15
15
use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
@@ -1422,9 +1422,6 @@ impl<'a> Parser<'a> {
1422
1422
} else if this. is_try_block ( ) {
1423
1423
this. expect_keyword ( kw:: Try ) ?;
1424
1424
this. parse_try_block ( lo)
1425
- } else if this. is_gen_block ( ) {
1426
- this. expect_keyword ( kw:: Gen ) ?;
1427
- this. parse_gen_block ( lo)
1428
1425
} else if this. eat_keyword ( kw:: Return ) {
1429
1426
this. parse_expr_return ( )
1430
1427
} else if this. eat_keyword ( kw:: Continue ) {
@@ -1446,12 +1443,14 @@ impl<'a> Parser<'a> {
1446
1443
if this. check_keyword ( kw:: Async ) {
1447
1444
if this. is_async_block ( ) {
1448
1445
// Check for `async {` and `async move {`.
1449
- this. parse_async_block ( )
1446
+ this. parse_gen_block ( )
1450
1447
} else {
1451
1448
this. parse_expr_closure ( )
1452
1449
}
1453
1450
} else if this. eat_keyword ( kw:: Await ) {
1454
1451
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 ( ) }
1455
1454
} else {
1456
1455
this. parse_expr_lit ( )
1457
1456
}
@@ -3043,14 +3042,6 @@ impl<'a> Parser<'a> {
3043
3042
}
3044
3043
}
3045
3044
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
-
3054
3045
fn is_do_catch_block ( & self ) -> bool {
3055
3046
self . token . is_keyword ( kw:: Do )
3056
3047
&& self . is_keyword_ahead ( 1 , & [ kw:: Catch ] )
@@ -3077,13 +3068,18 @@ impl<'a> Parser<'a> {
3077
3068
&& self . token . uninterpolated_span ( ) . at_least_rust_2024 ( )
3078
3069
}
3079
3070
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 > > {
3082
3073
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
+ } ;
3084
3080
let capture_clause = self . parse_capture_clause ( ) ?;
3085
3081
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 ) ;
3087
3083
Ok ( self . mk_expr_with_attrs ( lo. to ( self . prev_token . span ) , kind, attrs) )
3088
3084
}
3089
3085
@@ -3614,7 +3610,7 @@ impl MutVisitor for CondChecker<'_> {
3614
3610
| ExprKind :: Match ( _, _)
3615
3611
| ExprKind :: Closure ( _)
3616
3612
| ExprKind :: Block ( _, _)
3617
- | ExprKind :: Async ( _, _)
3613
+ | ExprKind :: Gen ( _ , _, _)
3618
3614
| ExprKind :: TryBlock ( _)
3619
3615
| ExprKind :: Underscore
3620
3616
| ExprKind :: Path ( _, _)
0 commit comments