Store original Attribute of the variants_from_header for spans

This commit is contained in:
David Tolnay 2021-04-22 13:09:19 -07:00
parent 0ffb76f5d6
commit 2b62812419
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 8 additions and 4 deletions

View File

@ -33,7 +33,7 @@ pub struct Parser<'a> {
pub namespace: Option<&'a mut Namespace>,
pub cxx_name: Option<&'a mut Option<ForeignName>>,
pub rust_name: Option<&'a mut Option<Ident>>,
pub variants_from_header: Option<&'a mut bool>,
pub variants_from_header: Option<&'a mut Option<Attribute>>,
// 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<Attribute>, 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")

View File

@ -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<Variant>,
pub variants_from_header: bool,
pub variants_from_header_attr: Option<Attribute>,
pub repr: Atom,
pub repr_type: Type,
pub explicit_repr: bool,

View File

@ -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,