Skip to content

Extraneous $ in macro by example matcher produces suggestion for nonsensica, syntactically invalid fix #157157

@LunarLambda

Description

@LunarLambda

Code

macro_rules! repro {
    ($($e:$expr),*) => {}
}

(note the extraneous `$` in `$e:$expr`)

Current output

error: missing fragment specifier
 --> src/lib.rs:2:11
  |
2 |     ($($e:$expr),*) => {}
  |           ^
  |
  = note: fragment specifiers must be provided
  = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`, along with `expr_2021` and `pat_param` for edition compatibility
help: try adding a specifier here
  |
2 |     ($($e:$:specexpr),*) => {}
  |            +++++

Desired output

Rationale and extra context

Ideally I would like the diagnostic to point out the $ as extraneous and simply suggest its removal. Or at the very least, produce something that is syntactically correct Rust. even if it's not the code the user "meant" to write.

Other cases

Rust Version

play.rust-lang.org, stable (1.96.0)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions