The restriction of what can follow a fragment does not apply to repetition

The little macro book says:

Repetitions also adhere to these restrictions, meaning if a repetition can repeat multiple times(* or +), then the contents must be able to follow themselves. If a repetition can repeat zero times (? or *) then what comes after the repetition must be able to follow what comes before.

Consider this example

macro_rules! impl_d{
    ($($e:expr)* )=>{
        
    };
}
fn main(){
  impl_d!(a b);
}

The rule stmt and expr: =>, ,, or ; does not apply to the repetition. If changing the definition of the macro to the following:

macro_rules! impl_d{
    ($e:expr $e2:expr )=>{
        
    };
}

Then an expected error will be reported

error: `$e:expr` is followed by `$e2:expr`, which is not allowed for `expr` fragments

Is the content of the little macro book outdated?

1 Like

I'm pretty sure this has to be a bug, because adjacent exprs are highly ambiguous: consider

impl_d!(a * b * c * d);

where it is ambiguous how many expressions there are and whether each * is a multiplication or a dereference. Searching the issue tracker, I find only this somewhat different case not tagged as a bug:

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.