From ab821aed0c048964a86285d534ca93203d61af89 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 2 Apr 2024 19:30:32 -0400 Subject: [PATCH] Fix precedence of postfix match --- compiler/rustc_ast/src/ast.rs | 3 ++- compiler/rustc_ast/src/util/parser.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index aba94f4d817..ccbcd5091b4 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1276,7 +1276,8 @@ pub fn precedence(&self) -> ExprPrecedence { ExprKind::While(..) => ExprPrecedence::While, ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop, ExprKind::Loop(..) => ExprPrecedence::Loop, - ExprKind::Match(..) => ExprPrecedence::Match, + ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match, + ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch, ExprKind::Closure(..) => ExprPrecedence::Closure, ExprKind::Block(..) => ExprPrecedence::Block, ExprKind::TryBlock(..) => ExprPrecedence::TryBlock, diff --git a/compiler/rustc_ast/src/util/parser.rs b/compiler/rustc_ast/src/util/parser.rs index 13768c12017..544db992f4f 100644 --- a/compiler/rustc_ast/src/util/parser.rs +++ b/compiler/rustc_ast/src/util/parser.rs @@ -281,6 +281,7 @@ pub enum ExprPrecedence { ForLoop, Loop, Match, + PostfixMatch, ConstBlock, Block, TryBlock, @@ -334,7 +335,8 @@ pub fn order(self) -> i8 { | ExprPrecedence::InlineAsm | ExprPrecedence::Mac | ExprPrecedence::FormatArgs - | ExprPrecedence::OffsetOf => PREC_POSTFIX, + | ExprPrecedence::OffsetOf + | ExprPrecedence::PostfixMatch => PREC_POSTFIX, // Never need parens ExprPrecedence::Array