Skip to content
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

missing_fragment_specifier points at the wrong span if followed by another metavariable #129077

Closed
tgross35 opened this issue Aug 14, 2024 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tgross35
Copy link
Contributor

tgross35 commented Aug 14, 2024

This:

macro_rules! foo {
    ($bar) => {};
    ($baz $qux:ident) => {};
}

Produces:

error: missing fragment specifier
 --> src/lib.rs:2:6
  |
2 |     ($bar) => {};
  |      ^^^^

...

error: missing fragment specifier
 --> src/lib.rs:3:11
  |
3 |     ($baz $qux:ident) => {};
  |           ^

Notice for the second pattern, the diagnostic points at $qux rather than $baz. $qux is not a problem here, the span should look similar to $bar.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=11ae576f5ce6e77fbad782f6c013ba76

Tested on both 1.80 and the 2024-08-13 nightly. This affects the new diagnostic that applies to e2024 added in #128006, as well as the existing lint (I noticed it looking at the reports in #128425).

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 14, 2024
@tgross35 tgross35 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 14, 2024
@tgross35
Copy link
Contributor Author

tgross35 commented Aug 14, 2024

It seems like the span at https://github.com/tgross35/rust/blob/2b78d920964e1d70927bcd208529bda0e11120d0/compiler/rustc_expand/src/mbe/macro_check.rs#L268 must be wrong, which means this might show up in other diagnostics too.

@fmease
Copy link
Member

fmease commented Aug 14, 2024

Duplicate of #95463.

@tgross35
Copy link
Contributor Author

Ah yup, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants