diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-12-28 22:22:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-28 22:22:19 +0100 |
| commit | c52d58f346aea2e2e7ed650ee95785d33500a6d0 (patch) | |
| tree | 4220254f810af0804181959838ff4eb500f68af0 /src/test | |
| parent | 0b7ed65c13064ff1afe334bb781c02d172f54a48 (diff) | |
| parent | d72a0c437bd2db922b954af7b0278e1f4bf31edf (diff) | |
| download | rust-c52d58f346aea2e2e7ed650ee95785d33500a6d0.tar.gz rust-c52d58f346aea2e2e7ed650ee95785d33500a6d0.zip | |
Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-errors
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..
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/macros/best-failure.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/macros/best-failure.stderr | 21 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/ui/macros/best-failure.rs b/src/test/ui/macros/best-failure.rs new file mode 100644 index 00000000000..bbdd465d5ec --- /dev/null +++ b/src/test/ui/macros/best-failure.rs @@ -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() {} diff --git a/src/test/ui/macros/best-failure.stderr b/src/test/ui/macros/best-failure.stderr new file mode 100644 index 00000000000..a52fc5e3da6 --- /dev/null +++ b/src/test/ui/macros/best-failure.stderr @@ -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 + |
