This PR adds a derive attribute #[enumset(no_super_impls)]. When this is used, deriving EnumSetType does not also implement Clone, Copy, Eq, or PartialEq. These traits must then be implemented some other way instead.
My use case is deriving EnumSetType for an enum generated by the prost crate, which allows extra derives to be added but always derives Clone, Copy, Eq, or PartialEq (among others). Without this no_super_impls option, this results in a compile error due to conflicting implementations of these traits.
I had also tried simply dropping the Copy + Eq requirement entirely, but that turned out to be impossible because:
#[derive(Eq)] on EnumSet<T> sets a bound of T: Eq on the generated Eq implementation (and likewise for PartialEq). Therefore, Eq and PartialEq must be implemented manually on EnumSet. This problem probably won't be solved any time soon.
EnumSet constants cannot be used in patterns if they use a non-derived Eq implementation:
error: to use a constant of type `enumset::EnumSet` in a pattern, `enumset::EnumSet` must be annotated with `#[derive(PartialEq, Eq)]`
--> enumset/tests/ops.rs:286:17
|
286 | CONST_SET => { /* ok */ }
| ^^^^^^^^^
This PR adds a derive attribute
#[enumset(no_super_impls)]
. When this is used, derivingEnumSetType
does not also implementClone
,Copy
,Eq
, orPartialEq
. These traits must then be implemented some other way instead.My use case is deriving
EnumSetType
for an enum generated by theprost
crate, which allows extra derives to be added but always derivesClone
,Copy
,Eq
, orPartialEq
(among others). Without thisno_super_impls
option, this results in a compile error due to conflicting implementations of these traits.I had also tried simply dropping the
Copy + Eq
requirement entirely, but that turned out to be impossible because:#[derive(Eq)]
onEnumSet<T>
sets a bound ofT: Eq
on the generatedEq
implementation (and likewise forPartialEq
). Therefore,Eq
andPartialEq
must be implemented manually onEnumSet
. This problem probably won't be solved any time soon.EnumSet
constants cannot be used in patterns if they use a non-derivedEq
implementation:😞