diff options
| author | Ross Smyth <crs2017@gmail.com> | 2024-02-15 19:54:35 -0500 |
|---|---|---|
| committer | Ross Smyth <crs2017@gmail.com> | 2024-03-05 23:34:45 -0500 |
| commit | 68a58f255ac7b7487769667fdd5fe2536f952c15 (patch) | |
| tree | 0498a02f581a2d3e057c8073d6280144abae0c71 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 62415e2a95a3b0f137636f86f6a904b8ed85798e (diff) | |
| download | rust-68a58f255ac7b7487769667fdd5fe2536f952c15.tar.gz rust-68a58f255ac7b7487769667fdd5fe2536f952c15.zip | |
Add postfix-match experimental feature
Co-authored-by: Josh Stone <jistone@redhat.com>
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 6cc358db9fc..02ff452473d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1375,6 +1375,12 @@ impl<'a> Parser<'a> { return Ok(self.mk_await_expr(self_arg, lo)); } + 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); + } + let fn_span_lo = self.token.span; let mut seg = self.parse_path_segment(PathStyle::Expr, None)?; self.check_trailing_angle_brackets(&seg, &[&token::OpenDelim(Delimiter::Parenthesis)]); @@ -2889,8 +2895,19 @@ impl<'a> Parser<'a> { /// Parses a `match ... { ... }` expression (`match` token already eaten). fn parse_expr_match(&mut self) -> PResult<'a, P<Expr>> { let match_span = self.prev_token.span; - let lo = self.prev_token.span; let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; + + self.parse_match_block(match_span, match_span, scrutinee) + } + + /// Parses 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>, + ) -> PResult<'a, P<Expr>> { if let Err(mut e) = self.expect(&token::OpenDelim(Delimiter::Brace)) { if self.token == token::Semi { e.span_suggestion_short( |
