about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-09-26 12:51:00 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-10-11 12:09:48 -0400
commitea468f427016bbf89819199bb8420afc27e64a7f (patch)
tree78d49c5c8f728631e73d1191cac3ef0f95038397 /src/test/codegen/src-hash-algorithm
parenta20ae8901c1160b4044dda803cb061630e2f8331 (diff)
downloadrust-ea468f427016bbf89819199bb8420afc27e64a7f.tar.gz
rust-ea468f427016bbf89819199bb8420afc27e64a7f.zip
Allow skipping extra paren insertion during AST pretty-printing
Fixes #74616
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