@@ -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 . psess . 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 ;
@@ -2897,16 +2898,17 @@ impl<'a> Parser<'a> {
2897
2898
let match_span = self . prev_token . span ;
2898
2899
let scrutinee = self . parse_expr_res ( Restrictions :: NO_STRUCT_LITERAL , None ) ?;
2899
2900
2900
- self . parse_match_block ( match_span, match_span, scrutinee)
2901
+ self . parse_match_block ( match_span, match_span, scrutinee, MatchKind :: Prefix )
2901
2902
}
2902
2903
2903
- /// Parses a `match expr { ... }` or a `expr.match { ... }` expression.
2904
- /// This is after the match token and scrutinee are eaten
2904
+ /// Parses the block of a `match expr { ... }` or a `expr.match { ... }`
2905
+ /// expression. This is after the match token and scrutinee are eaten
2905
2906
fn parse_match_block (
2906
2907
& mut self ,
2907
2908
lo : Span ,
2908
2909
match_span : Span ,
2909
2910
scrutinee : P < Expr > ,
2911
+ match_kind : MatchKind ,
2910
2912
) -> PResult < ' a , P < Expr > > {
2911
2913
if let Err ( mut e) = self . expect ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
2912
2914
if self . token == token:: Semi {
@@ -2950,15 +2952,15 @@ impl<'a> Parser<'a> {
2950
2952
} ) ;
2951
2953
return Ok ( self . mk_expr_with_attrs (
2952
2954
span,
2953
- ExprKind :: Match ( scrutinee, arms) ,
2955
+ ExprKind :: Match ( scrutinee, arms, match_kind ) ,
2954
2956
attrs,
2955
2957
) ) ;
2956
2958
}
2957
2959
}
2958
2960
}
2959
2961
let hi = self . token . span ;
2960
2962
self . bump ( ) ;
2961
- Ok ( self . mk_expr_with_attrs ( lo. to ( hi) , ExprKind :: Match ( scrutinee, arms) , attrs) )
2963
+ Ok ( self . mk_expr_with_attrs ( lo. to ( hi) , ExprKind :: Match ( scrutinee, arms, match_kind ) , attrs) )
2962
2964
}
2963
2965
2964
2966
/// Attempt to recover from match arm body with statements and no surrounding braces.
@@ -3967,7 +3969,7 @@ impl MutVisitor for CondChecker<'_> {
3967
3969
| ExprKind :: While ( _, _, _)
3968
3970
| ExprKind :: ForLoop { .. }
3969
3971
| ExprKind :: Loop ( _, _, _)
3970
- | ExprKind :: Match ( _, _)
3972
+ | ExprKind :: Match ( _, _, _ )
3971
3973
| ExprKind :: Closure ( _)
3972
3974
| ExprKind :: Block ( _, _)
3973
3975
| ExprKind :: Gen ( _, _, _)
0 commit comments