Preserve leading vert when pretty-printing patterns#76188
Preserve leading vert when pretty-printing patterns#76188Aaron1011 wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
compiler/rustc_ast/src/ast.rs
Outdated
There was a problem hiding this comment.
is vert terminology used elsewhere? Looking at the two TokenKinds (one in ast, one in rustc_lexer), the name for the thing is Or, so maybe stick with leading_or?
OTOH, I don't really enjoy and / or names for & and | symbols, so we might want to rename those (obviously, in a separate PR). In rust-analyzer, those are called amp and pipe, but vert or vbar also would work for | I think (although i do find vert specifically confusing a bit).
EDIT: to clarify on the naming thing: I don't like and / or because they name operations that the symbols somtimes represent, and not the symbols themselves. In contrast, ampersand & vertical bar are the names of the glyphs.
There was a problem hiding this comment.
The vert terminology is used in parse_top_pat, which is why I picked it.
|
I wonder if this should be ? |
Fixes rust-lang#76182 Previously, we did not preserve the precense of a leading vert ('|') when parsing a pattern. This lead to an instance of rust-lang#43081 when invoking a proc-macro, since the pretty-printed tokens would be missing the '|' present in the captured tokens.
b2e9fcc to
2b812b5
Compare
|
Perhaps it's possible to fixup this in |
Unfortunately, this is currently done by completely ignoring those tokens, regardless of the context. rust/compiler/rustc_parse/src/lib.rs Lines 335 to 359 in 58d5ce4 While I don't think there's any special danger of losing |
|
As a side node, I'm not very familiar with how the pretty-printer is used (outside of the 'probable equality' check). Is preserving these kinds of syntactic details generally considered desirable, or is removing things like leading |
|
I think the primary requirement is "the output of The second requirement is that the pretty-printed code builds (if it doesn't use hygiene), because some people apparently parse pretty-printed code (#57155 (comment)). The third (temporary) requirement is that it should be good enough for the proc macro pretty-print / reparse hack. Only the last requirement requires tokens to be printed precisely. |
|
@petrochenkov: Do you still prefer changing the 'probably equality' check to ignore vertical separators? |
|
@Aaron1011 |
|
Also, |
Fixes rust-lang#76182 This is an alternative to PR rust-lang#76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
|
@petrochenkov: I opened #76585, which ignores |
…chenkov Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes rust-lang#76182 This is an alternative to PR rust-lang#76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
…chenkov Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes rust-lang#76182 This is an alternative to PR rust-lang#76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
…chenkov Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes rust-lang#76182 This is an alternative to PR rust-lang#76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
…enkov Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes rust-lang#76182 This is an alternative to PR rust-lang#76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
Fixes #76182
Previously, we did not preserve the precense of a leading vert ('|')
when parsing a pattern. This lead to an instance of #43081 when invoking
a proc-macro, since the pretty-printed tokens would be missing the '|'
present in the captured tokens.