Skip to content

$a:tt $($b:tt)* is forbidden in macros #25436

Closed
@nikomatsakis

Description

@nikomatsakis

In an example like http://is.gd/TKfdKf:

macro_rules! foo {
  ( $a:tt $($b:tt)* ) => { }
}

fn main() { }

we report the following error:

<anon>:2:11: 2:19 error: `$a:tt` is followed by a sequence repetition, which is not allowed for `tt` fragments
<anon>:2   ( $a:tt $($b:tt)* ) => { }
                   ^~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101

This is part of the macro future-proofing code but it is an unnecessary limitation. For fragments that represent at most one token tree (tt, block, ident, possibly others) there is no concern at all about being following by sequence repetition. This turns out to be a really big limitation in practice, since making macros that work over a generic sequence of token trees effectively allows for arbitrary parsing.

cc @pnkfelix

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions