@@ -567,11 +567,11 @@ fn print_stmt(s: ps, st: ast::stmt) {
567
567
}
568
568
ast:: stmt_expr ( expr, _) {
569
569
space_if_not_bol ( s) ;
570
- print_tl_expr ( s, expr) ;
570
+ print_expr ( s, expr) ;
571
571
}
572
572
ast:: stmt_semi ( expr, _) {
573
573
space_if_not_bol ( s) ;
574
- print_tl_expr ( s, expr) ;
574
+ print_expr ( s, expr) ;
575
575
word ( s. s , ";" ) ;
576
576
}
577
577
}
@@ -609,7 +609,7 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type,
609
609
alt blk. node . expr {
610
610
some ( expr) {
611
611
space_if_not_bol ( s) ;
612
- print_tl_expr ( s, expr) ;
612
+ print_expr ( s, expr) ;
613
613
maybe_print_trailing_comment ( s, expr. span , some ( blk. span . hi ) ) ;
614
614
}
615
615
_ { }
@@ -697,37 +697,6 @@ fn print_mac(s: ps, m: ast::mac) {
697
697
}
698
698
}
699
699
700
- // An expression that begins with a dual-form statement/expression like `{
701
- // ... }-10` would be parsed as `{ ... };-10` unless parentheses are used (ie,
702
- // `({...}-10)`). These parentheses are not, however, preserved by the
703
- // parser. This function specifies whether parentheses must be inserted.
704
- fn print_tl_expr ( s : ps , & & expr: @ast:: expr ) {
705
- fn stmt_expr_requires_parens ( ex : @ast:: expr ) -> bool {
706
- fn helper ( ex : @ast:: expr , inner : bool ) -> bool {
707
- log ( debug, ( "helper" , ex, inner) ) ;
708
- if inner && !parse:: parser:: expr_requires_semi_to_be_stmt ( ex) {
709
- ret true ;
710
- }
711
- alt ex. node {
712
- ast:: expr_call ( subex, _, _) | ast:: expr_binary ( _, subex, _) {
713
- be helper ( subex, true ) ;
714
- }
715
- _ { ret false; }
716
- }
717
- }
718
- ret helper( ex, false ) ;
719
- }
720
-
721
- #debug ( "print_tl_expr %s" , expr_to_str ( expr) ) ;
722
- if stmt_expr_requires_parens ( expr) {
723
- popen ( s) ;
724
- print_expr ( s, expr) ;
725
- pclose ( s) ;
726
- } else {
727
- print_expr ( s, expr) ;
728
- }
729
- }
730
-
731
700
fn print_expr ( s : ps , & & expr: @ast:: expr ) {
732
701
maybe_print_comment ( s, expr. span . lo ) ;
733
702
ibox ( s, indent_unit) ;
@@ -1062,6 +1031,7 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
1062
1031
ast:: expr_copy ( _) | ast:: expr_assign ( _, _) | ast:: expr_be ( _) |
1063
1032
ast:: expr_assign_op ( _, _, _) | ast:: expr_swap ( _, _) |
1064
1033
ast:: expr_log ( _, _, _) | ast:: expr_assert ( _) |
1034
+ ast:: expr_call ( _, _, true ) |
1065
1035
ast:: expr_check ( _, _) { true }
1066
1036
_ { false }
1067
1037
} ;
@@ -1404,7 +1374,7 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
1404
1374
ast:: expr_assert ( _) { true }
1405
1375
ast:: expr_check ( _, _) { true }
1406
1376
ast:: expr_log ( _, _, _) { true }
1407
- _ { false }
1377
+ _ { ! parse : : parser :: expr_requires_semi_to_be_stmt ( expr ) }
1408
1378
}
1409
1379
}
1410
1380
0 commit comments