-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
$crate is treated as a normal identifier in a macro_rules matcher #147028
Copy link
Copy link
Open
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
I've found that, in some cases, inside a
macro_rulesmatcher (the thing on the left of the=>),$crateis treated as if it's a normal identifier, which seems very weird. I'm not sure if this is intended or a bug.This weirdness manifests in two different ways:
$crateon its own in the matcher is treated as literally matching$crate, as opposed to being a metavariable or erroring:$x:tthas the namex) such that the metavariable's name is$crate:See also #146967 and #146968 and #146114 for weirdness with
$crate.Meta
Reproducible on the playground with version
1.92.0-nightly (2025-09-24 caccb4d0368bd918ef66)