-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve leading vert when pretty-printing patterns #76188
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -550,6 +550,8 @@ pub struct Pat { | |||
pub id: NodeId, | |||
pub kind: PatKind, | |||
pub span: Span, | |||
/// Whether or not this pattern starts with a leading `|` | |||
pub leading_vert: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is vert
terminology used elsewhere? Looking at the two TokenKind
s (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.