-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-e…
…rrors Properly calculate best failure in macro matching 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..
- Loading branch information
Showing
6 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error: no rules expected the token `$` | ||
--> $DIR/best-failure.rs:4:30 | ||
| | ||
LL | macro_rules! number { | ||
| ------------------- when calling this macro | ||
... | ||
LL | number!(neg $signed, $self); | ||
| ^^^^^ no rules expected this token in macro call | ||
... | ||
LL | number! { false => u8; } | ||
| ------------------------ in this macro invocation | ||
| | ||
note: while trying to match meta-variable `$self:ident` | ||
--> $DIR/best-failure.rs:2:17 | ||
| | ||
LL | (neg false, $self:ident) => { $self }; | ||
| ^^^^^^^^^^^ | ||
= note: this error originates in the macro `number` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|