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 |
fitzgen
left a comment
There was a problem hiding this comment.
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! |
fitzgen
left a comment
There was a problem hiding this comment.
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 |
fitzgen
left a comment
There was a problem hiding this comment.
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: Arbitrarybounds added byarbitrary_derivewere 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
WrapperTraitalready 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 ondarlingas 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.boundthen the omitted types will have their bounds from the type declaration dropped. This mimicsserde.attributesfield ofTypeParam. I figured that replacing the fullTypeParamgives the most flexibility (even if it means duplicating attributes from the type declaration).