Skip to content

Commit ac100c2

Browse files
authored
Add comments to enum constructors too with @doc (#239)
Before this was only on the variants which is useless for WASM (it's wrapped around).
1 parent 710b79e commit ac100c2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/generation.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,9 @@ impl GenerationScope {
33443344
let variant_arg = variant.name_as_var();
33453345
let mut new_func = codegen::Function::new(&format!("new_{variant_arg}"));
33463346
new_func.vis("pub");
3347+
if let Some(doc) = &variant.doc {
3348+
new_func.doc(doc);
3349+
}
33473350
let can_fail = variant.rust_type().needs_bounds_check_if_inlined(types);
33483351
if !variant.rust_type().is_fixed_value() {
33493352
new_func.arg(&variant_arg, variant.rust_type().for_wasm_param(types));
@@ -6225,7 +6228,9 @@ fn codegen_group_choices(
62256228
// TODO: verify if variant.serialize_as_embedded_group impacts ctor generation
62266229
let mut new_func = codegen::Function::new(&format!("new_{}", variant.name_as_var()));
62276230
new_func.vis("pub");
6228-
6231+
if let Some(doc) = &variant.doc {
6232+
new_func.doc(doc);
6233+
}
62296234
let mut output_comma = false;
62306235
// We only want to generate Variant::new() calls when we created a special struct
62316236
// for the variant, which happens in the general case for multi-field group choices
@@ -6995,6 +7000,9 @@ fn generate_enum(
69957000
// new (particularly useful if we have encoding variables)
69967001
let mut new_func = codegen::Function::new(&format!("new_{variant_var_name}"));
69977002
new_func.vis("pub");
7003+
if let Some(doc) = &variant.doc {
7004+
new_func.doc(doc);
7005+
}
69987006
let mut output_comma = false;
69997007
let (mut init_fields, can_fail) = match &variant.data {
70007008
EnumVariantData::RustType(ty) => {

0 commit comments

Comments
 (0)