Skip to content

Macros do not accept empty vis at the end of the token tree #131950

Open
@ChayimFriedman2

Description

I tried this code:

macro_rules! m {
    ( ($v:vis) ) => {};
}

fn main() {
    m!( () );
}

I expected to see this happen: the code compile successfully. The reference says vis is "a possibly empty Visibility qualifier", so it should match empty.

Instead, this happened: the code is rejected with:

error: no rules expected the token `)`
 --> src/main.rs:6:10
  |
1 | macro_rules! m {
  | -------------- when calling this macro
...
6 |     m!( () );
  |          ^ no rules expected this token in macro call
  |
note: while trying to match meta-variable `$v:vis`
 --> src/main.rs:2:8
  |
2 |     ( ($v:vis) ) => {};
  |        ^^^^^^

Playground.

@rustbot label +A-macros

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-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.WG-macrosWorking group: Macros

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions