-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Properly calculate best failure in macro matching #105570
Conversation
r? @davidtwco (rustbot has picked a reviewer for you, use r? to override) |
For reference, this is the current terrible error for the added UI test, which caught my attention as someone was confused and asking about this on the community discord server: macro_rules! number {
(neg false, $self:ident) => { $self };
($signed:tt => $ty:ty;) => {
number!(neg $signed, $self);
//~^ ERROR no rules expected the token `$`
};
}
number! { false => u8; }
fn main() {}
|
This comment has been minimized.
This comment has been minimized.
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream.
c1609f8
to
d72a0c4
Compare
r? compiler |
Thanks, this explanation...
... elucidates the error. Gotta love macro variables. @bors r+ |
} | ||
|
||
impl BestFailure { | ||
fn is_better_position(&self, position: usize) -> 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.
The polarity of this fn is a bit confusing -- it reads as it's asking the question "is self better than position
", but it's actually "is position better than self
"?
LL | macro_rules! number { | ||
| ------------------- when calling this macro | ||
... | ||
LL | number!(neg $signed, $self); |
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.
kind of a shame that we highlight the whole $self
metavariable rather than just the $
token given the primary message of this diagnostic, but w/e
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#104402 (Move `ReentrantMutex` to `std::sync`) - rust-lang#104493 (available_parallelism: Gracefully handle zero value cfs_period_us) - rust-lang#105359 (Make sentinel value configurable in `library/std/src/sys_common/thread_local_key.rs`) - rust-lang#105497 (Clarify `catch_unwind` docs about panic hooks) - rust-lang#105570 (Properly calculate best failure in macro matching) - rust-lang#105702 (Format only modified files) - rust-lang#105998 (adjust message on non-unwinding panic) - rust-lang#106161 (Iterator::find: link to Iterator::position in docs for discoverability) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…-errors Shrink `ParseResult` in the hot path. rust-lang#105570 increased the size, which caused regressions. This uses the existing generic infrastructure to differentiate between the hot path and the diagnostics path.
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream.
We now try to properly use the location in the token stream.
This needs a little cleanup as the
best_failure
field is getting out of hand but it should be mostly good to go. I hope I didn't violate too many abstraction boundaries..