Skip to content

nested macros don't allow repetitions in binding patterns #35853

Closed
@colin-kiegel

Description

@colin-kiegel

Example:

macro_rules! foo {
    () => {
        macro_rules! bar {
            ( $( $any:tt )* ) => { $( $any )* };
        }
    };
}

fn main() { foo!(); }

https://play.rust-lang.org/?gist=f7355a6828cc2af68cc17f280a982ad8&version=beta&backtrace=0

results in:

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth

 --> <anon>:4:15
  |
4 |             ( $( $any:tt )* ) => { $( $any )* };
  |               ^^^^^^^^^^^^

Note

If the repetition is removed, i.e. the offending part ( $( $any:tt )* ) => { $( $any )* }; is changed to ( $any:tt ) => { $any };, the error disappears on rustc 1.12+ due to the fix of #6994: macros should be parsed more lazily. I find it a bit inconsistent, that nested macros now support binding patterns, but no repetitions.

Meta

  • rustc 1.12.0-beta.1 (822166b 2016-08-16)
  • rustc 1.13.0-nightly (499484f 2016-08-18)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions