diff --git a/gen/src/write.rs b/gen/src/write.rs index 7a910f10..fc6801c2 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -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, "}};"); diff --git a/macro/src/expand.rs b/macro/src/expand.rs index 79d678bc..e6773b5b 100644 --- a/macro/src/expand.rs +++ b/macro/src/expand.rs @@ -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 }; }) }); diff --git a/syntax/mod.rs b/syntax/mod.rs index 009afee8..0fc7a9d1 100644 --- a/syntax/mod.rs +++ b/syntax/mod.rs @@ -167,6 +167,7 @@ pub struct Receiver { } pub struct Variant { + pub doc: Doc, pub name: Pair, pub discriminant: Discriminant, pub expr: Option, diff --git a/syntax/parse.rs b/syntax/parse.rs index 009c3dfe..ab17be40 100644 --- a/syntax/parse.rs +++ b/syntax/parse.rs @@ -199,12 +199,14 @@ fn parse_variant( variant: RustVariant, discriminants: &mut DiscriminantSet, ) -> Result { + 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,