-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling Arbitrary on structs containing the Never type (!) #331
Comments
I think you're looking to restrict generation to just the two variants that don't contain a
does this address your use case or is there some dependency between |
Ideally, we're able to instantiate both For the It is possible (as you mentioned) to make two different strategies, but it doesn't seem possible to One workaround is to make our own never type - then it allows impling arbitrary. #[derive(Clone, Debug)]
enum Never {}
impl Arbitrary for Wrapper<Never> {
type Parameters = ();
type Strategy = impl Strategy<Value = Self>;
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
proptest::sample::select(vec![
Wrapper::<Never>::B,
Wrapper::<Never>::C,
])
}
} I think it would be nice if we could get proptest-rs to work nicely with coherence rules to allow for
I also additionally think it would be nice if |
I see. I think a negative impl for
I'm not as convinced on adding this to the derive impl at the moment but I'll think it over a bit more |
Let me know if this works for you. you'll need to use proptest with features |
Hello! Here's a motivating example
I'd like to be able to create such a
Wrapper
struct such that forWrapper<!>
, the proptest arbitrary picks between the other two options. This of course fails withWhich makes sense! Impling arbitrary on
!
doesn't particularly make sense since it can't be instantiated. Perhaps I can implementArbitrary
manually with separate impls for<T: Arbitrary>
andT = !
.Unfortunately, this also doesn't work because
I briefly tried using https://doc.rust-lang.org/beta/unstable-book/language-features/negative-impls.html to
impl !Arbitrary for ! {}
- but this does not work for avoiding this coherence detection.Any ideas on how this could work?
Perhaps
proptest_derive
could be augmented to detect this scenario and loosen the requirement thatT: Arbitrary
. Another idea could be something in the same vein as#[proptest(skip)]
onWrapper::A(T)
that only skips it for the uninhabited case.The text was updated successfully, but these errors were encountered: