rust-lang / rust-lang/reference

Metavariable repetition in the matcher and the transcriber

Open
#1,671 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-macros
Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

According to chapter 3.1., a metavariable must appear in exactly the same number, kind, and nesting order of repetitions in the transcriber as it did in the matcher. Based on this, I expected the following code (playground) not to compile, but it does compile without error.

macro_rules! repeat1 {
    ($($x:expr),+) => {
        $(let _ = $x;)*
    };
}
    
macro_rules! repeat2 {
    ($($x:expr),+) => {
        $(let _ = $x;)?
    };
}

macro_rules! repeat3 {
    ($($x:expr),*) => {
        $(let _ = $x;)?
    };
}
    
fn main() {
    repeat1!(1,2,3); 
    repeat2!(1,2,3); 
    repeat3!(1,2,3); 
}

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 with chapter 3.1 of the Rust Reference and reproduce the repeat1, repeat2, and repeat3 examples from the issue or its playground link. Compare the stated metavariable repetition rule with the observed compiler behavior, then determine whether the Reference wording or the documented examples need correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.