@@ -703,11 +703,23 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
703
703
}
704
704
}
705
705
706
+ // ret and fail, without arguments cannot appear is the discriminant of if,
707
+ // alt, do, & while unambiguously without being parenthesized
708
+ fn print_maybe_parens_discrim ( s : & ps , e : & @ast:: expr ) {
709
+ let disambig = alt e. node {
710
+ ast:: expr_ret ( option:: none. ) { true }
711
+ _ { false }
712
+ } ;
713
+ if disambig { popen ( s) }
714
+ print_expr ( s, e) ;
715
+ if disambig { pclose ( s) }
716
+ }
717
+
706
718
fn print_if ( s : & ps , test : & @ast:: expr , blk : & ast:: blk ,
707
719
elseopt : & option:: t < @ast:: expr > , chk : bool ) {
708
720
head ( s, "if" ) ;
709
721
if chk { word_nbsp ( s, "check" ) ; }
710
- print_expr ( s, test) ;
722
+ print_maybe_parens_discrim ( s, test) ;
711
723
space ( s. s ) ;
712
724
print_block ( s, blk) ;
713
725
fn do_else ( s : & ps , els : option:: t < @ast:: expr > ) {
@@ -869,7 +881,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
869
881
}
870
882
ast:: expr_while ( test, blk) {
871
883
head ( s, "while" ) ;
872
- print_expr ( s, test) ;
884
+ print_maybe_parens_discrim ( s, test) ;
873
885
space ( s. s ) ;
874
886
print_block ( s, blk) ;
875
887
}
@@ -897,7 +909,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
897
909
cbox ( s, alt_indent_unit) ;
898
910
ibox ( s, 4 u) ;
899
911
word_nbsp ( s, "alt" ) ;
900
- print_expr ( s, expr) ;
912
+ print_maybe_parens_discrim ( s, expr) ;
901
913
space ( s. s ) ;
902
914
bopen ( s) ;
903
915
for arm: ast:: arm in arms {
0 commit comments