Skip to content

Macro parsing ambiguity rules overly strict about repetition of the same token #24827

Closed
@joshtriplett

Description

@joshtriplett

RFC 550 (https://github.com/rust-lang/rfcs/blob/master/text/0550-macro-future-proofing.md) restricted macro syntax to future-proof against changes to Rust syntax. However, this breaks a case that can be handled unambiguously, namely repetition of the same token that splits off the rightmost rather than leftmost item:

macro_rules! foo {
    () => ( ... );
    ( $($init:ident)* $last:ident ) => ( ... foo! { $($init)* } );
}

This produces the following error:
error: local ambiguity: multiple parsing options: built-in NTs ident ('init') or ident ('last') or 0 other options.

This kind of syntax is useful for recursively parsing a list and repeatedly dropping the last item (rather than repeatedly dropping the first).

Rust should be able to handle this case unambiguously, as long as the repeated token type can't match the closing delimiter of the macro, which ident clearly never will.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions