about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-14 00:26:50 +0000
committerbors <bors@rust-lang.org>2020-10-14 00:26:50 +0000
commit4ba5068815137eef403383582d3f17f3b6802217 (patch)
tree1d8b7619774abe52c162e43db1c8d02226a2e37f /src/test/codegen/src-hash-algorithm
parentf243a2ad904705a1e340a08639dca105605b4175 (diff)
parent9a6ea386472acb7e1e1dd24370ef9d60d07463f5 (diff)
downloadrust-4ba5068815137eef403383582d3f17f3b6802217.tar.gz
rust-4ba5068815137eef403383582d3f17f3b6802217.zip
Auto merge of #77135 - Aaron1011:pretty-ignore-paren, r=petrochenkov
Refactor AST pretty-printing to allow skipping insertion of extra parens

Fixes #75734
Makes progress towards #43081
Unblocks PR #76130

When pretty-printing an AST node, we may insert additional parenthesis
to ensure that precedence is properly preserved in code we output.
However, the proc macro implementation relies on comparing a
pretty-printed AST node to the captured `TokenStream`. Inserting extra
parenthesis changes the structure of the reparsed `TokenStream`, making
the comparison fail.

This PR refactors the AST pretty-printing code to allow skipping the
insertion of additional parenthesis. Several freestanding methods are
moved to trait methods on `PrintState`, which keep track of an internal
`insert_extra_parens` flag. This flag is normally `true`, but we expose
a public method which allows pretty-printing a nonterminal with
`insert_extra_parens = false`.

To avoid changing the public interface of `rustc_ast_pretty`, the
freestanding `_to_string` methods are changed to delegate to a
newly-crated `State`. The main pretty-printing code is moved to a new
`state` module to ensure that it does not accidentally call any of these
public helper functions (instead, the internal functions with the same
name should be used).
Diffstat (limited to 'src/test/codegen/src-hash-algorithm')
0 files changed, 0 insertions, 0 deletions