Skip to content

Commit f1c53da

Browse files
authored
Rollup merge of #124269 - scrabsha:sasha/fix-124206, r=dtolnay
Pretty-print parenthesis around binary in postfix match Fixes #124206.
2 parents 7a58674 + c8ff8a4 commit f1c53da

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'a> State<'a> {
488488
self.space();
489489
}
490490
MatchKind::Postfix => {
491-
self.print_expr_as_cond(expr);
491+
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX, fixup);
492492
self.word_nbsp(".match");
493493
}
494494
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
use std::ops::Add;
10+
11+
//@ pretty-mode:expanded
12+
//@ pp-exact:precedence.pp
13+
14+
macro_rules! repro { ($e:expr) => { $e.match { _ => {} } }; }
15+
16+
struct Struct {}
17+
18+
impl Add<Struct> for usize {
19+
type Output = ();
20+
fn add(self, _: Struct) -> () { () }
21+
}
22+
pub fn main() {
23+
let a;
24+
(
25+
{ 1 } + 1).match {
26+
_ => {}
27+
};
28+
(4 as usize).match { _ => {} };
29+
(return).match { _ => {} };
30+
(a = 42).match { _ => {} };
31+
(|| {}).match { _ => {} };
32+
(42..101).match { _ => {} };
33+
(1 + Struct {}).match { _ => {} };
34+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(postfix_match)]
2+
3+
use std::ops::Add;
4+
5+
//@ pretty-mode:expanded
6+
//@ pp-exact:precedence.pp
7+
8+
macro_rules! repro {
9+
($e:expr) => {
10+
$e.match {
11+
_ => {}
12+
}
13+
};
14+
}
15+
16+
struct Struct {}
17+
18+
impl Add<Struct> for usize {
19+
type Output = ();
20+
fn add(self, _: Struct) -> () {
21+
()
22+
}
23+
}
24+
pub fn main() {
25+
let a;
26+
27+
repro!({ 1 } + 1);
28+
repro!(4 as usize);
29+
repro!(return);
30+
repro!(a = 42);
31+
repro!(|| {});
32+
repro!(42..101);
33+
repro!(1 + Struct {});
34+
}

0 commit comments

Comments
 (0)