Skip to content

Macro "missing fragment specifier" when accidentally prefixed with $ #155505

@DanielEScherzer

Description

@DanielEScherzer

Code

#[allow(unused)]
macro_rules! demo {
    ( $test:$tt ) => {
        
    }
}

Current output

Compiling playground v0.0.1 (/playground)
error: missing fragment specifier
 --> src/lib.rs:3:13
  |
3 |     ( $test:$tt ) => {
  |             ^
  |
  = 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
  |
3 |     ( $test:$:spectt ) => {
  |              +++++

error: could not compile `playground` (lib) due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error: missing fragment specifier
 --> src/lib.rs:3:13
  |
3 |     ( $test:$tt ) => {
  |             ^
  |
  = 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: fragment specifiers should not be prefixed with $
  |
3 |     ( $test:tt ) => {
  |             -

error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

I accidentally wrote $test:$tt instead of $test:tt and the suggestion was to add :spec in the wrong place, but even if the place was fixed given that I was trying to add the fragment specifier the error message should adjust for that

Other cases

Rust Version

Stable 1.95.0 via playground

Anything else?

No response

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