-
Notifications
You must be signed in to change notification settings - Fork 75
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
Allow trait bounds to be manually specified #138
Conversation
Not sure if I want to support this feature: but yeah I'd rather not have a bound on |
|
I just pushed a commit to remove If you think the updated implementation looks OK I would still love to merge this. For large codebases implementing dozens of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM, thanks.
I think I've been convinced that it is reasonable to support, if only because of the prior art of serde
supporting this. @Manishearth do you feel strongly that this feature shouldn't be supported? Otherwise, I'm inclined to merge.
2e0ee67
to
1c6d77a
Compare
Thanks for the review and the consideration @fitzgen 😊 I just rebased on |
If there are no objections from @Manishearth, perhaps we can merge soon @fitzgen? 🙏 |
Yeah I'm +1 |
Comments addressed, ready for re-review. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I've been on vacation. LGTM, modulo the nitpicks about returning errors instead of panicking I just noticed below.
Thanks @fitzgen! I've updated all of those panics to errors. For the error on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! And thanks for your patience with this one.
Tests are failing in CI: https://github.com/rust-fuzz/arbitrary/actions/runs/4369258606/jobs/7659042814#step:5:93
|
Tests passing locally now, should be good to go 🤞 |
Omg feels great to merge it, thank you for your patience Nick and Manish 😌 |
Could we do a v1.2.4 release of |
Published new release! |
While working with some generic types I found that the
T: Arbitrary
bounds added byarbitrary_derive
were too restrictive.Consider a trait that requires
Arbitrary
, like this:And a struct that uses it:
The derive macro currently generates an impl like:
Even though
WrapperTrait
already impliesArbitrary<'arbitrary>
via the universal lifetime quantifier, the compiler doesn't seem to be smart enough to work out that the bound is redundant. We get an error like this:Taking a leaf out of
serde
's book, this PR adds abound = ".."
container attribute which allows manually overriding the inferred bound. In our examplearbitrary(bound = "T: WrapperTrait")
works as expected. See the test case in./tests/bound.rs
.Implementation notes
I've added a dependency ondarling
as I find it much easier to write proc macro code with it. I could switch to vanillasyn
(or another macro crate) if you would prefer not to depend ondarling
.bound
then the omitted types will have their bounds from the type declaration dropped. This mimicsserde
.attributes
field ofTypeParam
. I figured that replacing the fullTypeParam
gives the most flexibility (even if it means duplicating attributes from the type declaration).