Closed
Description
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
^