diff --git a/syntax/attrs.rs b/syntax/attrs.rs index a1ad03cc..539cfd72 100644 --- a/syntax/attrs.rs +++ b/syntax/attrs.rs @@ -33,7 +33,7 @@ pub struct Parser<'a> { pub namespace: Option<&'a mut Namespace>, pub cxx_name: Option<&'a mut Option>, pub rust_name: Option<&'a mut Option>, - pub variants_from_header: Option<&'a mut bool>, + pub variants_from_header: Option<&'a mut Option>, // Suppress clippy needless_update lint ("struct update has no effect, all // the fields in the struct have already been specified") when preemptively @@ -130,7 +130,7 @@ pub fn parse(cx: &mut Errors, attrs: Vec, mut parser: Parser) -> Othe cx.push(err); } if let Some(variants_from_header) = &mut parser.variants_from_header { - **variants_from_header = true; + **variants_from_header = Some(attr); continue; } } else if attr.path.is_ident("allow") diff --git a/syntax/mod.rs b/syntax/mod.rs index 1eae19e1..dd5de522 100644 --- a/syntax/mod.rs +++ b/syntax/mod.rs @@ -37,7 +37,7 @@ use self::symbol::Symbol; use proc_macro2::{Ident, Span}; use syn::punctuated::Punctuated; use syn::token::{Brace, Bracket, Paren}; -use syn::{Expr, Generics, Lifetime, LitInt, Token, Type as RustType}; +use syn::{Attribute, Expr, Generics, Lifetime, LitInt, Token, Type as RustType}; pub use self::atom::Atom; pub use self::derive::{Derive, Trait}; @@ -112,6 +112,7 @@ pub struct Enum { pub brace_token: Brace, pub variants: Vec, pub variants_from_header: bool, + pub variants_from_header_attr: Option, pub repr: Atom, pub repr_type: Type, pub explicit_repr: bool, diff --git a/syntax/parse.rs b/syntax/parse.rs index c17cd6e2..bcf75ef0 100644 --- a/syntax/parse.rs +++ b/syntax/parse.rs @@ -187,7 +187,7 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Api { let mut namespace = namespace.clone(); let mut cxx_name = None; let mut rust_name = None; - let mut variants_from_header = false; + let mut variants_from_header = None; let attrs = attrs::parse( cx, item.attrs, @@ -246,6 +246,8 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Api { lifetimes: Punctuated::new(), gt_token: None, }; + let variants_from_header_attr = variants_from_header; + let variants_from_header = variants_from_header_attr.is_some(); Api::Enum(Enum { doc, @@ -258,6 +260,7 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Api { brace_token, variants, variants_from_header, + variants_from_header_attr, repr, repr_type, explicit_repr,