about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbwmf2 <bwmf2@protonmail.com>2023-02-26 23:22:50 +0100
committerbwmf2 <bwmf2@protonmail.com>2023-03-02 21:58:49 +0100
commit832b33e6b1e0359130b67f0c83f2def0420a6832 (patch)
tree4ee06bd97e3a94d073b8cc655feb7210ab6feb58
parent13471d3b2046cce78181dde6cfc146c09f55e29e (diff)
downloadrust-832b33e6b1e0359130b67f0c83f2def0420a6832.tar.gz
rust-832b33e6b1e0359130b67f0c83f2def0420a6832.zip
Force parentheses around `match` expression in binary expression
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state/expr.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index cacfe9eb2f1..a4d91a95662 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -244,6 +244,10 @@ impl<'a> State<'a> {
             (&ast::ExprKind::Let { .. }, _) if !parser::needs_par_as_let_scrutinee(prec) => {
                 parser::PREC_FORCE_PAREN
             }
+            // For a binary expression like `(match () { _ => a }) OP b`, the parens are required
+            // otherwise the parser would interpret `match () { _ => a }` as a statement,
+            // with the remaining `OP b` not making sense. So we force parens.
+            (&ast::ExprKind::Match(..), _) => parser::PREC_FORCE_PAREN,
             _ => left_prec,
         };