File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
branches/try/src/libsyntax/print Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
3
3
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4
- refs/heads/try: c67a34b9e509b76ff145526f28a20f9495c2ab61
4
+ refs/heads/try: c0c6af7f073620aacfb103c070e997a8d50b7201
5
5
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
6
6
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
7
7
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -1555,6 +1555,21 @@ impl<'a> State<'a> {
1555
1555
self . pclose ( )
1556
1556
}
1557
1557
1558
+ pub fn check_expr_bin_needs_paren ( & mut self , sub_expr : & ast:: Expr ,
1559
+ binop : ast:: BinOp ) -> bool {
1560
+ match sub_expr. node {
1561
+ ast:: ExprBinary ( ref sub_op, _, _) => {
1562
+ if ast_util:: operator_prec ( sub_op. node ) <
1563
+ ast_util:: operator_prec ( binop. node ) {
1564
+ true
1565
+ } else {
1566
+ false
1567
+ }
1568
+ }
1569
+ _ => true
1570
+ }
1571
+ }
1572
+
1558
1573
pub fn print_expr_maybe_paren ( & mut self , expr : & ast:: Expr ) -> io:: Result < ( ) > {
1559
1574
let needs_par = needs_parentheses ( expr) ;
1560
1575
if needs_par {
@@ -1670,10 +1685,18 @@ impl<'a> State<'a> {
1670
1685
op : ast:: BinOp ,
1671
1686
lhs : & ast:: Expr ,
1672
1687
rhs : & ast:: Expr ) -> io:: Result < ( ) > {
1673
- try!( self . print_expr_maybe_paren ( lhs) ) ;
1688
+ if self . check_expr_bin_needs_paren ( lhs, op) {
1689
+ try!( self . print_expr_maybe_paren ( lhs) ) ;
1690
+ } else {
1691
+ try!( self . print_expr ( lhs) ) ;
1692
+ }
1674
1693
try!( space ( & mut self . s ) ) ;
1675
1694
try!( self . word_space ( ast_util:: binop_to_string ( op. node ) ) ) ;
1676
- self . print_expr_maybe_paren ( rhs)
1695
+ if self . check_expr_bin_needs_paren ( rhs, op) {
1696
+ self . print_expr_maybe_paren ( rhs)
1697
+ } else {
1698
+ self . print_expr ( rhs)
1699
+ }
1677
1700
}
1678
1701
1679
1702
fn print_expr_unary ( & mut self ,
You can’t perform that action at this time.
0 commit comments