rust-fuzz/arbitrary

Add a way to opt-out of arbitrary::Arbitrary bound

Closed this issue · 2 comments

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:

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 🙂

closing as completed by #175