diff options
| author | Ross Smyth <crs2017@gmail.com> | 2024-02-17 12:43:54 -0500 |
|---|---|---|
| committer | Ross Smyth <crs2017@gmail.com> | 2024-03-06 00:35:19 -0500 |
| commit | 78b3bf98c3425d139b42a6326701573ff98b1a1f (patch) | |
| tree | 225c8c9365517efde4a2913b550f989593481c86 /compiler/rustc_parse/src | |
| parent | 68a58f255ac7b7487769667fdd5fe2536f952c15 (diff) | |
| download | rust-78b3bf98c3425d139b42a6326701573ff98b1a1f.tar.gz rust-78b3bf98c3425d139b42a6326701573ff98b1a1f.zip | |
Add MatchKind member to the Match expr for pretty printing & fmt
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 02ff452473d..e9c1bc7ad56 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -11,7 +11,7 @@ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; use ast::mut_visit::{noop_visit_expr, MutVisitor}; use ast::token::IdentIsRaw; -use ast::{CoroutineKind, ForLoopKind, GenBlockKind, Pat, Path, PathSegment}; +use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment}; use core::mem; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; @@ -1375,10 +1375,11 @@ impl<'a> Parser<'a> { return Ok(self.mk_await_expr(self_arg, lo)); } + // Post-fix match if self.eat_keyword(kw::Match) { let match_span = self.prev_token.span; self.psess.gated_spans.gate(sym::postfix_match, match_span); - return self.parse_match_block(lo, match_span, self_arg); + return self.parse_match_block(lo, match_span, self_arg, MatchKind::Postfix); } let fn_span_lo = self.token.span; @@ -2897,16 +2898,17 @@ impl<'a> Parser<'a> { let match_span = self.prev_token.span; let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; - self.parse_match_block(match_span, match_span, scrutinee) + self.parse_match_block(match_span, match_span, scrutinee, MatchKind::Prefix) } - /// Parses a `match expr { ... }` or a `expr.match { ... }` expression. - /// This is after the match token and scrutinee are eaten + /// Parses the block of a `match expr { ... }` or a `expr.match { ... }` + /// expression. This is after the match token and scrutinee are eaten fn parse_match_block( &mut self, lo: Span, match_span: Span, scrutinee: P<Expr>, + match_kind: MatchKind, ) -> PResult<'a, P<Expr>> { if let Err(mut e) = self.expect(&token::OpenDelim(Delimiter::Brace)) { if self.token == token::Semi { @@ -2950,7 +2952,7 @@ impl<'a> Parser<'a> { }); return Ok(self.mk_expr_with_attrs( span, - ExprKind::Match(scrutinee, arms), + ExprKind::Match(scrutinee, arms, match_kind), attrs, )); } @@ -2958,7 +2960,7 @@ impl<'a> Parser<'a> { } let hi = self.token.span; self.bump(); - Ok(self.mk_expr_with_attrs(lo.to(hi), ExprKind::Match(scrutinee, arms), attrs)) + Ok(self.mk_expr_with_attrs(lo.to(hi), ExprKind::Match(scrutinee, arms, match_kind), attrs)) } /// Attempt to recover from match arm body with statements and no surrounding braces. @@ -3967,7 +3969,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::While(_, _, _) | ExprKind::ForLoop { .. } | ExprKind::Loop(_, _, _) - | ExprKind::Match(_, _) + | ExprKind::Match(_, _, _) | ExprKind::Closure(_) | ExprKind::Block(_, _) | ExprKind::Gen(_, _, _) |
