virtue icon indicating copy to clipboard operation
virtue copied to clipboard

Enum variant fields are not allowed to be `pub`, so `EnumValue::add_pub_field` generates invalid Rust

Open NightEule5 opened this issue 8 months ago • 0 comments

When implementing generics, I found an oversight in enum generation:

generator
    .generate_enum("Foo")
    .add_value("Bar")
    .add_pub_field("bar", "u32");

// Generates:
enum Foo {
    Bar {
        pub bar: u32
    }
}

This does not compile, as the variant fields inherit the visibility of their parent enum:

error[E0449]: visibility qualifiers are not permitted here
 --> ...
  |
3 |         pub bar: u32
  |         ^^^
  |
  = note: enum variants and their fields always share the visibility of the enum they are in

This method appears to have been copied over from the struct generator code, as the documentation refers to structs. But it should be removed (or deprecated) from the enum variant code.

NightEule5 avatar Jun 11 '24 01:06 NightEule5