Add a way to opt-out of arbitrary::Arbitrary bound
Closed this issue · 2 comments
benluelo commented
Currently, deriving Arbitrary
on a type will enforce a bound of arbitrary::Arbitrary
on all of the generic types: https://github.com/rust-fuzz/arbitrary/blob/main/derive/src/lib.rs#L136-L145
This can be problematic if you have types like this:
trait Trait {
type Assoc: Arbitrary;
}
struct ImplsTrait {}
impl Trait for ImplsTrait {
type Assoc = Whatever;
}
// this derive will add a bound T: Arbitrary<'arbitrary>, even though it is never used
#[derive(Arbitrary)]
struct UsesAssoc<T: Trait> {
pub assoc: T::Assoc,
}
two possible solutions:
- implement something similar to serde's bound attribute: https://serde.rs/container-attrs.html#bound
- only bound the non-defaulted fields of the struct/ variant deriving
Arbitrary
benluelo commented
Oh wow, I just realized there's already an arbitrary(bound)
attribute. Perhaps some improvements to the docs are in order, I will open a PR for it 🙂