-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std: Remove #[old_orphan_check] from PartialEq #23288
Conversation
r? @aturon |
r? @gankro (rust_highfive has picked a reviewer for you, use r? to override) |
One possible way to retain the impl<T, U> PartialEq<T, U> for &[T] where U: RhsSlice { .. } And then |
I think for now we wouldn't necessarily want to commit to a trait like that, but it should be a backwards compatible extension to allow comparison of slices to more types, right? Another option would be to leverage |
Another idea (cc @nikomatsakis): change the
Advantages
Disadvantages:
|
Oh wow, that is an interesting idea! Some thoughts:
Curious what others think though! |
I though about this and I think is possible to maintain the evaluation order in the "reverse" case with the help of temporaries. Updated algorithm:
Yes, it's unfortunate. I think the right way to ensure symmetry is to use the type system: (a) use a blanket implementation like I mentioned above (issue: overlapping impls), or (b) make the compiler automatically derive the reverse case even if it has to bypass the orphan_check (can this lead to a violation of coherence?). |
Hm yeah, I'd be fine with that.
I would personally see this as pushing the envelope of a "bit too much magic" for a case that may not be worth it. |
☔ The latest upstream changes (presumably #23104) made this pull request unmergeable. Please resolve the merge conflicts. |
df746cc
to
b2d7837
Compare
I think we may want to consider some compiler help for symmetry, as @japaric is proposing, at some point in the future but there's just not scope for it right now. For the time being, I think we should move forward on this PR so that we can remove the feature gate, and then separately consider simpler workarounds like the blanket impl @japaric initially suggested. |
So, the thing that makes me most uncomfortable here is the removal of two-sides checks on That said, I don't think there's a strong reason for All that said... I'm not really sure what else to do. Once generic conversion traits land, we could perhaps use something like the Thoughts? |
I agree that this makes me feel a little uneasy, but I also agree that this impl would be fine to land as well: impl<T, R: As<[T]>> PartialEq<R> for [T] {
fn eq(&self, other: &R) -> bool { ... }
} |
OK, let's stage this after the conversion trait implementation, which is in progress. (Might be good in the meantime to quickly try this with |
FWIW, I think I agree with @aturon's assessment of "maybe we can improve this in the future but we should move forward for now". It is mildly annoying that you have to put the vec on the left, though I wonder if this will just be a thing that people get used to. (The orphan rules strongly suggest that you should favor the LHS for the more "specific" type...) |
For posterity, it looks like
|
☔ The latest upstream changes (presumably #23654) made this pull request unmergeable. Please resolve the merge conflicts. |
b2d7837
to
b24825b
Compare
☔ The latest upstream changes (presumably #23796) made this pull request unmergeable. Please resolve the merge conflicts. |
b24825b
to
ee24884
Compare
ping @aturon, this likely needs a decision pretty soon. |
This is a deprecated attribute that is slated for removal, and it also affects all implementors of the trait. This commit removes the attribute and fixes up implementors accordingly. The primary implementation which was lost was the ability to compare `&[T]` and `Vec<T>` (in that order). This change also modifies the `assert_eq!` macro to not consider both directions of equality, only the one given in the left/right forms to the macro. This modification is motivated due to the fact that `&[T] == Vec<T>` no longer compiles, causing hundreds of errors in unit tests in the standard library (and likely throughout the community as well). cc rust-lang#19470 [breaking-change]
be173f8
to
608fff8
Compare
⌛ Testing commit 608fff8 with merge 1a48efc... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry rollup |
This is a deprecated attribute that is slated for removal, and it also affects all implementors of the trait. This commit removes the attribute and fixes up implementors accordingly. The primary implementation which was lost was the ability to compare `&[T]` and `Vec<T>` (in that order). This change also modifies the `assert_eq!` macro to not consider both directions of equality, only the one given in the left/right forms to the macro. This modification is motivated due to the fact that `&[T] == Vec<T>` no longer compiles, causing hundreds of errors in unit tests in the standard library (and likely throughout the community as well). Closes rust-lang#19470 [breaking-change]
This is a deprecated attribute that is slated for removal, and it also affects
all implementors of the trait. This commit removes the attribute and fixes up
implementors accordingly. The primary implementation which was lost was the
ability to compare
&[T]
andVec<T>
(in that order).This change also modifies the
assert_eq!
macro to not consider both directionsof equality, only the one given in the left/right forms to the macro. This
modification is motivated due to the fact that
&[T] == Vec<T>
no longercompiles, causing hundreds of errors in unit tests in the standard library (and
likely throughout the community as well).
Closes #19470
[breaking-change]