diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-15 10:59:06 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-15 10:59:06 +0200 |
| commit | 8c83ea564bb7da5300c2e39afc87fcffb1e1d252 (patch) | |
| tree | b834c8c8460aacf31f568f2c0e1c09d8f7ee6000 /src/comp/syntax | |
| parent | d0d322ac9378ddda52a1c7112cd6809f1bbffa6e (diff) | |
| download | rust-8c83ea564bb7da5300c2e39afc87fcffb1e1d252.tar.gz rust-8c83ea564bb7da5300c2e39afc87fcffb1e1d252.zip | |
More thorough check for (.. 10).x in pretty-printer
Closes #919
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 667f1255fde..8ac8ccbdba2 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -882,13 +882,10 @@ fn print_expr(s: ps, expr: @ast::expr) { } ast::expr_field(expr, id) { // Deal with '10.x' - alt expr.node { - ast::expr_lit(@{node: ast::lit_int(_), _}) { + if ends_in_lit_int(expr) { popen(s); print_expr(s, expr); pclose(s); - } - _ { + } else { print_expr_parens_if_unary_or_ret(s, expr); - } } word(s.s, "."); word(s.s, id); @@ -1638,6 +1635,25 @@ fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str { ret s; } +fn ends_in_lit_int(ex: @ast::expr) -> bool { + alt ex.node { + ast::expr_lit(@{node: ast::lit_int(_), _}) { true } + ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) | + ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) | + ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) | + ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) | + ast::expr_log(_, sub) | ast::expr_assert(sub) | ast::expr_uniq(sub) | + ast::expr_check(_, sub) { ends_in_lit_int(sub) } + ast::expr_fail(osub) | ast::expr_ret(osub) | ast::expr_put(osub) { + alt osub { + some(ex) { ends_in_lit_int(ex) } + _ { false } + } + } + _ { false } + } +} + // // Local Variables: // mode: rust |
