-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove TrailingToken
.
#127842
Remove TrailingToken
.
#127842
Conversation
@@ -3262,7 +3262,7 @@ impl<'a> Parser<'a> { | |||
id: DUMMY_NODE_ID, | |||
is_placeholder: false, | |||
}, | |||
TrailingToken::None, | |||
false, |
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.
I would expect a next_token == token::Comma
here, because match arms are separated by commas.
I suspect this may cause issues with configured out arms inside derive/cfg_eval.
#[cfg_eval]
#[proc_macro_that_tries_to_parse_it_again] // will fail with a syntax error because the comma
// is not removed from the token representation?
fn foo() {
match 10 {
#[cfg(FALSE)]
10 => true,
_ => false,
}
}
// We just ate the comma, so no need to use `TrailingToken` | ||
Ok((param, TrailingToken::None)) | ||
// We just ate the comma, so no need to capture the trailing token. | ||
Ok((param, false)) |
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.
Including commas into the node
's tokens in node1, node2, node3
doesn't feel right, but maybe it's ok if proc macro attributes are not supported on this kind of nodes, only cfg
s.
That's assuming a proc macro should only see node
's tokens without comma, and cfg(FALSE)
should remove tokens including tokens.
On the other hand, proc macros probably should see the trailing comma as a part of their input, so they could correctly expand into nothing if necessary, like cfg(FALSE)
.
That would be a change in behavior, but it should only affect unstable proc macros (?).
That would eliminate the need in TrailingToken::MaybeComma
entirely, because the commas would always be included and would never be trailing.
Okay, maybe I'm a bit confused about the way in which the current machinery works, because it's not very consistent. If we parse like this collect_tokens(parse_expr);
eat_comma(); then we should pass If we parse like this collect_tokens(parse_expr_and_comma); then we should pass Either way the comma will be collected, just through slightly different means, and will be included into the token stream for the expression. I'm actually not sure anymore, will the commas appear in the token streams that [#[my_proc_macro] a, #[my_proc_macro] b, #[my_proc_macro] c]; in the first two invocations? |
I'm not sure the answers to your questions. This is meant to be a refactoring that just relies on local code reasoning. E.g. for this code: TrailingToken::Semi => {
assert_eq!(self.token.kind, token::Semi);
true
} It's a bit silly to assert that |
As a refactoring this looks good to me, even if the pre-existing behavior is somewhat questionable. |
☔ The latest upstream changes (presumably #127892) made this pull request unmergeable. Please resolve the merge conflicts. |
It's used in `Parser::collect_tokens_trailing_token` to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool. Also, the `TrailingToken::Gt` case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by the `TrailingToken::MaybeComma` case, and it effectively is in the new code.
a35189d
to
487802d
Compare
I fixed the mistaken case and rebased. @bors r=petrochenkov rollup |
Rollup of 7 pull requests Successful merges: - rust-lang#127491 (Migrate 8 very similar FFI `run-make` tests to rmake) - rust-lang#127687 (Const-to-pattern-to-MIR cleanup) - rust-lang#127822 (Migrate `issue-85401-static-mir`, `missing-crate-dependency` and `unstable-flag-required` `run-make` tests to rmake) - rust-lang#127842 (Remove `TrailingToken`.) - rust-lang#127864 (cleanup: remove support for 3DNow! cpu features) - rust-lang#127899 (Mark myself as on leave) - rust-lang#127901 (Add missing GHA group for building `llvm-bitcode-linker`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127842 - nnethercote:rm-TrailingToken, r=petrochenkov Remove `TrailingToken`. It's used in `Parser::collect_tokens_trailing_token` to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool. Also, the `TrailingToken::Gt` case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by the `TrailingToken::MaybeComma` case, and it effectively is in the new code. r? `@petrochenkov`
It's used in
Parser::collect_tokens_trailing_token
to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool.Also, the
TrailingToken::Gt
case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by theTrailingToken::MaybeComma
case, and it effectively is in the new code.r? @petrochenkov