Skip to content

macro fragment names are no longer idents #42019

Closed
@durka

Description

@durka

This is a stable-to-beta regression, but it's such a weird thing to do that I don't know if it counts.

Consider the following code (playpen):

macro_rules! gen {
    ($name:ident ($($dol:tt $var:ident)*) $($body:tt)*) => {
        macro_rules! $name {
            ($($dol $var:ident)*) => {
                $($body)*
            }
        }
    }
}

The gen macro parses a macro argument spec by matching a dollar sign with $dol and the fragment name with $var. Then (in this toy example) it just regurgitates that adding :ident as the type of each fragment.

This works in 1.17, but fails when invoked in 1.18 and nightly with the message "expected identifier, found [the ident passed in for $var]", pointing at $var on line 4. All three channels work if $var:ident is changed to $var:tt on line 2.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions