Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 151 forks source link

When implementing `EnumString` on nested enum it requires `Default` implementation for nested enums #388

Open bWanShiTong opened 1 month ago

bWanShiTong commented 1 month ago

Code required to reproduce:

use strum::EnumString;

#[derive(Debug, Clone, Copy, EnumString)]
enum Nested {
    EnumA(EnumA),
    EnumB(EnumB),
}

#[derive(Debug, Clone, Copy, EnumString)]
enum EnumA {
    Variant1,
    Variant2,
}

#[derive(Debug, Clone, Copy, EnumString)]
enum EnumB {
    Variant3,
    Variant4,
}

fn main() {}

Error:

error[E0277]: the trait bound `EnumA: Default` is not satisfied
 --> src/main.rs:3:30
  |
3 | #[derive(Debug, Clone, Copy, EnumString)]
  |                              ^^^^^^^^^^ the trait `Default` is not implemented for `EnumA`
  |
  = note: this error originates in the derive macro `EnumString` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `EnumB: Default` is not satisfied
 --> src/main.rs:3:30
  |
3 | #[derive(Debug, Clone, Copy, EnumString)]
  |                              ^^^^^^^^^^ the trait `Default` is not implemented for `EnumB`
  |
  = note: this error originates in the derive macro `EnumString` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `testing` (bin "testing") due to 2 previous errors