Files
rust/src/libsyntax
bors d6ad402a64 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.
2017-09-08 06:56:09 +00:00
..
2017-08-30 01:38:54 +03:00
2017-09-01 12:46:37 -05:00
2017-09-01 12:46:37 -05:00
2017-05-24 16:40:03 -04:00
2017-09-05 18:46:21 -07:00
2017-05-07 01:20:15 -07:00
2017-08-30 01:38:54 +03:00
2017-08-30 01:38:54 +03:00
2016-11-21 09:00:56 +00:00
2017-09-01 14:39:46 -05:00
2017-09-01 12:46:37 -05:00
2017-08-30 01:38:54 +03:00
2017-08-25 16:18:21 -04:00
2017-06-07 12:15:39 +09:00
2017-08-30 01:38:54 +03:00
2017-08-30 01:38:54 +03:00
2017-08-30 01:38:54 +03:00
2017-08-30 01:38:54 +03:00
2017-07-28 15:46:26 +02:00