Skip to content

_ gets greedily consumed in macro pattern matching repetitions #7056

@DropDemBits

Description

@DropDemBits

In a repetition of a rule (e.g. expr, ident) that can cover _, and matching a _ directly, the _ is matched by the repetition causing the _ rule to fail and produces an expected leaf: `_` error.

rustc on the latest stable and nightly matches these macro invocations without any errors.

Minimal reproducible examples:

Example 1

macro_rules! seq1 {
    ($($a:ident)* _) => {};
}

// `_` overlaps with `$a:ident` but rustc matches it under the `_` token
seq1![a b c d _]; // expected leaf: `_`

Example 2

macro_rules! seq2 {
    ($($a:expr => $b:ident)* _ => $c:expr) => {};
}

// `_ => ou` overlaps with `$a:expr => $b:ident` but rustc matches it under `_ => $c:expr`
seq2![a => b c => d _ => ou]; // expected leaf: `_`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions