rust-lang / rust-lang/rust

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

Open
#131,950 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macros C-bug T-compiler T-lang WG-macros
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the Rust reproducer in src/main.rs or the linked Playground and confirm that an empty vis at the end of the token tree is rejected. Trace the macro-by-example matching behavior described in the report; done means the example compiles successfully while preserving the documented behavior of vis metavariables.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.