about summary refs log tree commit diff
path: root/src/liballoc/string.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-08 06:56:09 +0000
committerbors <bors@rust-lang.org>2017-09-08 06:56:09 +0000
commitd6ad402a644d9e57f1a6d6c579fe04acf00e0e2e (patch)
tree36cb0612f6c81b1301d70a22841f8bb5355df1de /src/liballoc/string.rs
parente1ef1882a0b1e37d51d1b864bc8222897977d692 (diff)
parent3454d99cb6355ab60c95e72d96e04eb9c69a6138 (diff)
downloadrust-d6ad402a644d9e57f1a6d6c579fe04acf00e0e2e.tar.gz
rust-d6ad402a644d9e57f1a6d6c579fe04acf00e0e2e.zip
Auto merge of #43742 - epdtry:pprust-expr-fix, r=petrochenkov
pprust: fix parenthesization of exprs

The pretty printer in `syntax::print::pprust` currently relies on the presence of `ExprKind::Paren` hints in order to correctly parenthesize expressions in its output.  If `Paren` nodes are missing, it sometimes produces wrong output, such as printing `1 - (2 - 3)` as `1 - 2 - 3`.  This PR fixes `pprust` to correctly print expressions regardless of the presence or absence of `Paren` nodes.  This should make `pprust` easier to use with programmatically constructed ASTs.

A few notes:

 * I added a function for assigning precedence values to exprs in `syntax::util::parser`, since there is already code there for assigning precedence values to binops.  Let me know if I should move this somewhere more `pprust`-specific.

 * I also moved the `contains_exterior_struct_lit` function from `rustc_lint::unused::UnusedParens` into `syntax::util::parser`, since it's needed for determining the correct parenthesization of `if`/`while` conditional expressions.

 * I couldn't find a good way to compare two exprs for equivalence while ignoring semantically-irrelevant details like spans.  So the test for the new behavior relies on a slight hack: it adds `Paren` nodes everywhere, so that the pretty-printed version exactly reflects the structure of the AST, and then compares the printed strings.  This works, but let me know if there's a better way.
Diffstat (limited to 'src/liballoc/string.rs')
0 files changed, 0 insertions, 0 deletions