Skip to content

meta matches pseudo-identifiers #59881

Open
@gnzlbg

Description

@gnzlbg

This (playground) fails:

macro_rules! foo {
    ($($m:meta => $i:item)* _ => $j:item) => {};
}

foo! {
    _ => { fn f() -> i32 { 2 } }
}

fn main() { f(); }
error: local ambiguity: multiple parsing options: built-in NTs meta ('m') or 1 other option.
 --> src/main.rs:6:5
  |
6 |     _ => { fn f() -> i32 { 2 } }
  |     ^

This also fails (playground):

macro_rules! foo {
    ($m:meta) => {};
    (_ => { $i:item }) => {
        $i
    };
}

foo! {
    _ => { fn f() -> i32 { 2 } }
}

fn main() {  f(); }
error: expected identifier, found reserved identifier `_`
 --> src/main.rs:9:5
  |
9 |     _ => { fn f() -> i32 { 2 } }
  |     ^ expected identifier, found reserved identifier

I believe both cases should work because meta should not match pseudo-identifiers.

cc @petrochenkov @Centril @nrc @alexcrichton

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions