@@ -11,7 +11,7 @@ use crate::errors;
11
11
use crate :: maybe_recover_from_interpolated_ty_qpath;
12
12
use ast:: mut_visit:: { noop_visit_expr, MutVisitor } ;
13
13
use ast:: token:: IdentIsRaw ;
14
- use ast:: { CoroutineKind , ForLoopKind , GenBlockKind , Pat , Path , PathSegment } ;
14
+ use ast:: { CoroutineKind , ForLoopKind , GenBlockKind , MatchKind , Pat , Path , PathSegment } ;
15
15
use core:: mem;
16
16
use rustc_ast:: ptr:: P ;
17
17
use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
@@ -1375,10 +1375,11 @@ impl<'a> Parser<'a> {
1375
1375
return Ok ( self . mk_await_expr ( self_arg, lo) ) ;
1376
1376
}
1377
1377
1378
+ // Post-fix match
1378
1379
if self . eat_keyword ( kw:: Match ) {
1379
1380
let match_span = self . prev_token . span ;
1380
1381
self . sess . gated_spans . gate ( sym:: postfix_match, match_span) ;
1381
- return self . parse_match_block ( lo, match_span, self_arg) ;
1382
+ return self . parse_match_block ( lo, match_span, self_arg, MatchKind :: Postfix ) ;
1382
1383
}
1383
1384
1384
1385
let fn_span_lo = self . token . span ;
@@ -2895,16 +2896,17 @@ impl<'a> Parser<'a> {
2895
2896
let match_span = self . prev_token . span ;
2896
2897
let scrutinee = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
2897
2898
2898
- self . parse_match_block ( match_span, match_span, scrutinee)
2899
+ self . parse_match_block ( match_span, match_span, scrutinee, MatchKind :: Prefix )
2899
2900
}
2900
2901
2901
- /// Parses a `match expr { ... }` or a `expr.match { ... }` expression.
2902
- /// This is after the match token and scrutinee are eaten
2902
+ /// Parses the block of a `match expr { ... }` or a `expr.match { ... }`
2903
+ /// expression. This is after the match token and scrutinee are eaten
2903
2904
fn parse_match_block (
2904
2905
& mut self ,
2905
2906
lo : Span ,
2906
2907
match_span : Span ,
2907
2908
scrutinee : P < Expr > ,
2909
+ match_kind : MatchKind ,
2908
2910
) -> PResult < ' a , P < Expr > > {
2909
2911
if let Err ( mut e) = self . expect ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
2910
2912
if self . token == token:: Semi {
@@ -2948,15 +2950,15 @@ impl<'a> Parser<'a> {
2948
2950
} ) ;
2949
2951
return Ok ( self . mk_expr_with_attrs (
2950
2952
span,
2951
- ExprKind :: Match ( scrutinee, arms) ,
2953
+ ExprKind :: Match ( scrutinee, arms, match_kind ) ,
2952
2954
attrs,
2953
2955
) ) ;
2954
2956
}
2955
2957
}
2956
2958
}
2957
2959
let hi = self . token . span ;
2958
2960
self . bump ( ) ;
2959
- Ok ( self . mk_expr_with_attrs ( lo. to ( hi) , ExprKind :: Match ( scrutinee, arms) , attrs) )
2961
+ Ok ( self . mk_expr_with_attrs ( lo. to ( hi) , ExprKind :: Match ( scrutinee, arms, match_kind ) , attrs) )
2960
2962
}
2961
2963
2962
2964
/// Attempt to recover from match arm body with statements and no surrounding braces.
@@ -3946,7 +3948,7 @@ impl MutVisitor for CondChecker<'_> {
3946
3948
| ExprKind :: While ( _, _, _)
3947
3949
| ExprKind :: ForLoop { .. }
3948
3950
| ExprKind :: Loop ( _, _, _)
3949
- | ExprKind :: Match ( _, _)
3951
+ | ExprKind :: Match ( _, _, _ )
3950
3952
| ExprKind :: Closure ( _)
3951
3953
| ExprKind :: Block ( _, _)
3952
3954
| ExprKind :: Gen ( _, _, _)
0 commit comments