mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-27 17:30:38 +00:00
Merge pull request #616 from dtolnay/doc
Preserve doc comments on enum variants
This commit is contained in:
commit
f90cc999de
@ -357,6 +357,9 @@ fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) {
|
||||
write_atom(out, enm.repr);
|
||||
writeln!(out, " {{");
|
||||
for variant in &enm.variants {
|
||||
for line in variant.doc.to_string().lines() {
|
||||
writeln!(out, " //{}", line);
|
||||
}
|
||||
writeln!(out, " {} = {},", variant.name.cxx, variant.discriminant);
|
||||
}
|
||||
writeln!(out, "}};");
|
||||
|
@ -280,9 +280,11 @@ fn expand_enum(enm: &Enum) -> TokenStream {
|
||||
let repr = enm.repr;
|
||||
let type_id = type_id(&enm.name);
|
||||
let variants = enm.variants.iter().map(|variant| {
|
||||
let doc = &variant.doc;
|
||||
let variant_ident = &variant.name.rust;
|
||||
let discriminant = &variant.discriminant;
|
||||
Some(quote! {
|
||||
#doc
|
||||
pub const #variant_ident: Self = #ident { repr: #discriminant };
|
||||
})
|
||||
});
|
||||
|
@ -167,6 +167,7 @@ pub struct Receiver {
|
||||
}
|
||||
|
||||
pub struct Variant {
|
||||
pub doc: Doc,
|
||||
pub name: Pair,
|
||||
pub discriminant: Discriminant,
|
||||
pub expr: Option<Expr>,
|
||||
|
@ -199,12 +199,14 @@ fn parse_variant(
|
||||
variant: RustVariant,
|
||||
discriminants: &mut DiscriminantSet,
|
||||
) -> Result<Variant> {
|
||||
let mut doc = Doc::new();
|
||||
let mut cxx_name = None;
|
||||
let mut rust_name = None;
|
||||
attrs::parse(
|
||||
cx,
|
||||
&variant.attrs,
|
||||
attrs::Parser {
|
||||
doc: Some(&mut doc),
|
||||
cxx_name: Some(&mut cxx_name),
|
||||
rust_name: Some(&mut rust_name),
|
||||
..Default::default()
|
||||
@ -233,6 +235,7 @@ fn parse_variant(
|
||||
let expr = variant.discriminant.map(|(_, expr)| expr);
|
||||
|
||||
Ok(Variant {
|
||||
doc,
|
||||
name,
|
||||
discriminant,
|
||||
expr,
|
||||
|
Loading…
Reference in New Issue
Block a user