Skip to content

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

Closed
@tgross35

Description

@tgross35

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions