mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-24 04:20:02 +00:00
Parse cxx_name and rust_name attributes on enum variants
This commit is contained in:
parent
e6f6214c00
commit
6bf9ef4749
@ -157,7 +157,7 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Result<
|
||||
let mut variants = Vec::new();
|
||||
let mut discriminants = DiscriminantSet::new(repr);
|
||||
for variant in item.variants {
|
||||
match parse_variant(variant, &mut discriminants) {
|
||||
match parse_variant(cx, variant, &mut discriminants) {
|
||||
Ok(variant) => variants.push(variant),
|
||||
Err(err) => cx.push(err),
|
||||
}
|
||||
@ -194,7 +194,23 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Result<
|
||||
}))
|
||||
}
|
||||
|
||||
fn parse_variant(variant: RustVariant, discriminants: &mut DiscriminantSet) -> Result<Variant> {
|
||||
fn parse_variant(
|
||||
cx: &mut Errors,
|
||||
variant: RustVariant,
|
||||
discriminants: &mut DiscriminantSet,
|
||||
) -> Result<Variant> {
|
||||
let mut cxx_name = None;
|
||||
let mut rust_name = None;
|
||||
attrs::parse(
|
||||
cx,
|
||||
&variant.attrs,
|
||||
attrs::Parser {
|
||||
cxx_name: Some(&mut cxx_name),
|
||||
rust_name: Some(&mut rust_name),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
match variant.fields {
|
||||
Fields::Unit => {}
|
||||
_ => {
|
||||
@ -213,7 +229,7 @@ fn parse_variant(variant: RustVariant, discriminants: &mut DiscriminantSet) -> R
|
||||
Err(err) => return Err(Error::new_spanned(variant, err)),
|
||||
};
|
||||
|
||||
let name = pair(Namespace::ROOT, &variant.ident, None, None);
|
||||
let name = pair(Namespace::ROOT, &variant.ident, cxx_name, rust_name);
|
||||
let expr = variant.discriminant.map(|(_, expr)| expr);
|
||||
|
||||
Ok(Variant {
|
||||
|
Loading…
Reference in New Issue
Block a user