Skip to content

Commit 197f360

Browse files
committed
Ensure parens are wrapped around composite exprs in call/index/field pos
This is needed to fix the second example in issue #919
1 parent 8c83ea5 commit 197f360

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/comp/syntax/print/pprust.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn print_expr(s: ps, expr: @ast::expr) {
718718
pclose(s);
719719
}
720720
ast::expr_call(func, args) {
721-
print_expr_parens_if_unary_or_ret(s, func);
721+
print_expr_parens_if_not_bot(s, func);
722722
popen(s);
723723
commasep_exprs(s, inconsistent, args);
724724
pclose(s);
@@ -885,13 +885,13 @@ fn print_expr(s: ps, expr: @ast::expr) {
885885
if ends_in_lit_int(expr) {
886886
popen(s); print_expr(s, expr); pclose(s);
887887
} else {
888-
print_expr_parens_if_unary_or_ret(s, expr);
888+
print_expr_parens_if_not_bot(s, expr);
889889
}
890890
word(s.s, ".");
891891
word(s.s, id);
892892
}
893893
ast::expr_index(expr, index) {
894-
print_expr_parens_if_unary_or_ret(s, expr);
894+
print_expr_parens_if_not_bot(s, expr);
895895
word(s.s, "[");
896896
print_expr(s, index);
897897
word(s.s, "]");
@@ -993,10 +993,15 @@ fn print_expr(s: ps, expr: @ast::expr) {
993993
end(s);
994994
}
995995

996-
fn print_expr_parens_if_unary_or_ret(s: ps, ex: @ast::expr) {
996+
fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
997997
let parens = alt ex.node {
998998
ast::expr_fail(_) | ast::expr_ret(_) | ast::expr_put(_) |
999-
ast::expr_unary(_, _) { true }
999+
ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
1000+
ast::expr_ternary(_, _, _) | ast::expr_move(_, _) |
1001+
ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) |
1002+
ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
1003+
ast::expr_log(_, _) | ast::expr_assert(_) | ast::expr_uniq(_) |
1004+
ast::expr_check(_, _) { true }
10001005
_ { false }
10011006
};
10021007
if parens { popen(s); }

0 commit comments

Comments
 (0)