-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
PartialEq/Eq and PartialOrd/Ord impls generated by #[derive(...)]
are not generic for RHS
#20927
Comments
So, it turns out that implementing this isn't as straightforward as I thought it would be.
The generated So, I suppose this will have to wait until the |
@nikomatsakis would this run afoul of any of your coherence strategies? |
@murarth Is your branch available anywhere for perusal? |
@shepmaster: Sure. It's severely outdated at this point and the standard library won't compile with it, but other than that, it worked. https://github.com/murarth/rust/tree/derive-generic |
This is impossible to do by-default now, since it is backwards incompatible. At least, it is if we don't do something like However, I could definitely imagine adding an opt-in way to do this. |
Here's @huonw's example of the backwards incompatibility from our IRC conversation: struct Foo<T> { ... }
/* manual impl */
impl<T> PartialEq for Foo<T> { ... }
#[derive(PartialEq)]
struct Bar<T> {
x: Foo<T>,
} |
One concrete idea was extending the derive syntax: #[derive(PartialEq(with-awesome-flexibility))]
struct Foo<T> { ... } |
Triage; no change |
I agree that this could be handled better by the derives in the standard library. Thanks for the discussion! Since this has a potential to interact in confusing ways with type inference, I would prefer to see this explored in an RFC. There are at least two promising ways to go with this, either by making the derived impls smarter out of the box (which will hinge on what happens with rust-lang/rfcs#917) or by requiring the programmer to tweak the derived impl using attributes. |
(Partial)Eq
and(Partial)Ord
traits are now generic for right-hand side expression, but derive-generated code has not caught up. That is,Option<T>
is only comparable to otherOption<T>
instances, rather than anyOption<U> where T: Eq<U>
.I'm currently working on implementing this myself; however, as I am not familiar with the code, I'm still working out the cleanest way to get it done. I suppose I'm wondering whether anyone has any advice or if anyone is already working on this or some other changes to
derive
that might include this.The text was updated successfully, but these errors were encountered: