Refactor AST pretty-printing to allow skipping insertion of extra parens#77135
Refactor AST pretty-printing to allow skipping insertion of extra parens#77135bors merged 5 commits intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
Let's do a Crater run to be on the safe side. @bors try |
|
⌛ Trying commit 88ef6bd26cd4d9d864295faf26ddd890c51f39f1 with merge 89a6ec545e5f85c102ce8eae663f1abae5e6e8b8... |
|
☀️ Try build successful - checks-actions, checks-azure |
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
@Aaron1011 |
88ef6bd to
9910556
Compare
|
@petrochenkov: I've addressed your comments |
|
@craterbot abort |
|
🗑️ Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Moving |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
|
|
There are a few actix-web regressions that were missed by the check, due to a weird directory structure or being in another fork (e.g. @petrochenkov I could extend the check, but it looks like we've covered nearly all of the regressions. This should should be ready to merge. |
|
@bors r+ |
|
📌 Commit 9a6ea38 has been approved by |
|
@bors rollup=never This will cause a (small) amount of breakage, so let's make it easy to bisect. |
|
☀️ Test successful - checks-actions, checks-azure |
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 extraparenthesis changes the structure of the reparsed
TokenStream, makingthe 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 internalinsert_extra_parensflag. This flag is normallytrue, but we exposea public method which allows pretty-printing a nonterminal with
insert_extra_parens = false.To avoid changing the public interface of
rustc_ast_pretty, thefreestanding
_to_stringmethods are changed to delegate to anewly-crated
State. The main pretty-printing code is moved to a newstatemodule to ensure that it does not accidentally call any of thesepublic helper functions (instead, the internal functions with the same
name should be used).