File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed
compiler/rustc_ast_pretty/src/pprust/state
tests/pretty/postfix-match Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,19 @@ impl<'a> State<'a> {
488488 self . space ( ) ;
489489 }
490490 MatchKind :: Postfix => {
491+ let need_par = expr. precedence ( ) . order ( ) >= parser:: PREC_RANGE
492+ && expr. precedence ( ) . order ( ) < parser:: PREC_PREFIX ;
493+
494+ if need_par {
495+ // avoid printing `a + b.match {}`, print
496+ // `(a + b).match {}` instead.
497+ self . popen ( ) ;
498+ }
491499 self . print_expr_as_cond ( expr) ;
500+ if need_par {
501+ self . pclose ( ) ;
502+ }
503+
492504 self . word_nbsp ( ".match" ) ;
493505 }
494506 }
Original file line number Diff line number Diff line change 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:precedence.pp
11+
12+ macro_rules! repro { ($e :expr) => { $e .match { _ => {} } }; }
13+
14+ pub fn main() {
15+ let a;
16+ (
17+ { 1 } + 1).match {
18+ _ => {}
19+ };
20+ (4 as usize).match { _ => {} };
21+ (return).match { _ => {} };
22+ (a = 42).match { _ => {} };
23+ (|| {}).match { _ => {} };
24+ (42..101).match { _ => {} };
25+ }
Original file line number Diff line number Diff line change 1+ #![ feature( postfix_match) ]
2+
3+ //@ pretty-mode:expanded
4+ //@ pp-exact:precedence.pp
5+
6+ macro_rules! repro {
7+ ( $e: expr) => {
8+ $e. match {
9+ _ => { }
10+ }
11+ } ;
12+ }
13+
14+ pub fn main ( ) {
15+ let a;
16+
17+ repro ! ( { 1 } + 1 ) ;
18+ repro ! ( 4 as usize ) ;
19+ repro ! ( return ) ;
20+ repro ! ( a = 42 ) ;
21+ repro ! ( || { } ) ;
22+ repro ! ( 42 ..101 ) ;
23+ }
File renamed without changes.
You can’t perform that action at this time.
0 commit comments