Skip to content

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

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

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Fields

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