-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
impl PartialEq<Vec<T>> for &'_ [T] / [T; N] #2917
Comments
Yes, the orphan rules. One is defined in libcore, the other is not.
Not really. The RFCs repo isn't really intended for questions. I encourage you to instead search rust-lang/rust repo or the general internet, then post questions on the user's forum or Discord. |
You can also check out the Rust source code and make the change yourself to see the compiler errors. |
My change seems to build & pass the tests...: diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index b4a9da84787..78dab89be79 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -2340,6 +2340,8 @@ macro_rules! __impl_slice_eq1 {
__impl_slice_eq1! { [] Vec<A>, Vec<B>, }
__impl_slice_eq1! { [] Vec<A>, &[B], }
__impl_slice_eq1! { [] Vec<A>, &mut [B], }
+__impl_slice_eq1! { [] &[A], Vec<B>, }
+__impl_slice_eq1! { [] &mut [A], Vec<B>, }
__impl_slice_eq1! { [] Cow<'_, [A]>, &[B], A: Clone }
__impl_slice_eq1! { [] Cow<'_, [A]>, &mut [B], A: Clone }
__impl_slice_eq1! { [] Cow<'_, [A]>, Vec<B>, A: Clone } |
Hmm. You know, there were changes in Rust 1.41 that changed some code in this area. See RFC 2451 for more details. Perhaps it is possible now? If your code compiles, passes tests, and you can write the equality tests you wanted to, it's worth opening a PR to rust-lang/rust. |
Sounds good! |
Would it also be possible to |
@mbrubeck when I tried similar for |
I can't see any reason that an impl for |
Also, there should be working |
Adding these impls to |
impl PartialEq<Vec<B>> for &[A], &mut [A] rust-lang/rfcs#2917
impl PartialEq<Vec<B>> for &[A], &mut [A] rust-lang/rfcs#2917
impl PartialEq<Vec<B>> for &[A], &mut [A] rust-lang/rfcs#2917
impl PartialEq<Vec<B>> for &[A], &mut [A] rust-lang/rfcs#2917
impl PartialEq<Vec<B>> for &[A], &mut [A] rust-lang/rfcs#2917
This can be closed now, right? |
Add PartialEq impls for Vec <-> slice This is a follow-up to rust-lang#71660 and rust-lang/rfcs#2917 to add two more missing vec/slice PartialEq impls: ``` impl<A, B> PartialEq<[B]> for Vec<A> where A: PartialEq<B> { .. } impl<A, B> PartialEq<Vec<B>> for [A] where A: PartialEq<B> { .. } ``` Since this is insta-stable, it should go through the `@rust-lang/libs` FCP process. Note that I used version 1.47.0 for the `stable` attribute because I assume this will not merge before the 1.46.0 branch is cut next week.
Currently:
Vec<T>
implementsPartialEq
for&'_ [B; N]
,&'_ [B]
,&'_ mut [B]
, and[B; N]
(see https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-PartialEq%3C%26%27_%20%5BB%3B%20N%5D%3E)[T; N]
implementsPartialEq
for&'b [B]
,&'b mut [B]
,[B; N]
, and[B]
(see https://doc.rust-lang.org/std/primitive.array.html#impl-PartialEq%3C%26%27b%20%5BB%5D%3E)&'b [B]
,&'b mut [B]
, and[B]
implementPartialEq<[A; N]>
(see https://doc.rust-lang.org/std/primitive.slice.html#impl-PartialEq%3C%5BA%3B%20N%5D%3E)[A]
implementsPartialEq<[B]>
(see https://doc.rust-lang.org/std/primitive.slice.html#impl-PartialEq%3C%5BA%3B%20N%5D%3E)But neither
[T; N]
,&'_ [T]
,&'_ mut [T]
, nor[T]
implementPartialEq<Vec<T>>
. This means that equality tests have to be pointlessly flipped. Is there any reason for this behavior? Would it be possible to fix this?The text was updated successfully, but these errors were encountered: