Skip to content

Commit 027d6f0

Browse files
committed
Pretty-print parenthesis around binary in postfix match
Signed-off-by: Sasha Pourcelot <[email protected]>
1 parent 7f2fc33 commit 027d6f0

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,18 @@ impl<'a> State<'a> {
488488
self.space();
489489
}
490490
MatchKind::Postfix => {
491+
let need_par = matches!(expr.kind, ast::ExprKind::Binary(_, _, _));
492+
493+
if need_par {
494+
// avoid printing `a + b.match {}`, print
495+
// `(a + b).match {}` instead.
496+
self.popen();
497+
}
491498
self.print_expr_as_cond(expr);
499+
if need_par {
500+
self.pclose();
501+
}
502+
492503
self.word_nbsp(".match");
493504
}
494505
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#![feature(postfix_match)]
4+
#[prelude_import]
5+
use ::std::prelude::rust_2015::*;
6+
#[macro_use]
7+
extern crate std;
8+
9+
//@ pretty-mode:expanded
10+
//@ pp-exact:issue-124206.pp
11+
12+
macro_rules! repro { ($e:expr) => { $e.match { _ => {} } }; }
13+
14+
pub fn main() { ({ 1 } + 1).match { _ => {} }; }
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(postfix_match)]
2+
3+
//@ pretty-mode:expanded
4+
//@ pp-exact:issue-124206.pp
5+
6+
macro_rules! repro {
7+
($e:expr) => {
8+
$e.match {
9+
_ => {}
10+
}
11+
};
12+
}
13+
14+
pub fn main() {
15+
repro!({ 1 } + 1);
16+
}

0 commit comments

Comments
 (0)