Skip to content

$( #[$attr:meta] )* $var:ident → error: local ambiguity: multiple parsing options #24189

Closed
@andersk

Description

@andersk

I’m writing a macro that parses enum declarations to work around #16920, and I’ve discovered that it can’t handle attributes on the enum variants like I thought it would. Specifically, the matcher $( #[$attr:meta] )* $var:ident fails to match #[doc = "Bar"] Baz, complaining “error: local ambiguity: multiple parsing options: built-in NTs ident ('var') or 1 other options.”

This doesn’t seem to make sense, since an ident cannot start with #.

Small test case:

#![crate_type = "lib"]

macro_rules! foo {
    (
        pub enum $name:ident {
            $( #[$attr:meta] )* $var:ident
        }
    ) => {
        pub enum $name {
            $( #[$attr] )* $var
        }
    };
}

foo! {
    pub enum Foo {
        #[doc = "Bar"] Baz
    }
}
$ rustc --version --verbose
rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)
binary: rustc
commit-hash: 9854143cba679834bc4ef932858cd5303f015a0e
commit-date: 2015-04-02
build-date: 2015-04-02
host: x86_64-unknown-linux-gnu
release: 1.0.0-beta
$ rustc r.rs
r.rs:17:9: 17:10 error: local ambiguity: multiple parsing options: built-in NTs ident ('var') or 1 other options.
r.rs:17         #[doc = "Bar"] Baz
                ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions