Skip to content

Commit 832b33e

Browse files
committed
Force parentheses around match expression in binary expression
1 parent 13471d3 commit 832b33e

File tree

1 file changed

+4
-0
lines changed
  • compiler/rustc_ast_pretty/src/pprust/state

1 file changed

+4
-0
lines changed

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ impl<'a> State<'a> {
244244
(&ast::ExprKind::Let { .. }, _) if !parser::needs_par_as_let_scrutinee(prec) => {
245245
parser::PREC_FORCE_PAREN
246246
}
247+
// For a binary expression like `(match () { _ => a }) OP b`, the parens are required
248+
// otherwise the parser would interpret `match () { _ => a }` as a statement,
249+
// with the remaining `OP b` not making sense. So we force parens.
250+
(&ast::ExprKind::Match(..), _) => parser::PREC_FORCE_PAREN,
247251
_ => left_prec,
248252
};
249253

0 commit comments

Comments
 (0)