Skip to content

feat: add symmetric PartialEq impls for Vec, &[T], &mut [T] versus Cow<'_, [T]>#156160

Open
kx0101 wants to merge 1 commit intorust-lang:mainfrom
kx0101:cow-vec-symmetric-partialeq
Open

feat: add symmetric PartialEq impls for Vec, &[T], &mut [T] versus Cow<'_, [T]>#156160
kx0101 wants to merge 1 commit intorust-lang:mainfrom
kx0101:cow-vec-symmetric-partialeq

Conversation

@kx0101
Copy link
Copy Markdown

@kx0101 kx0101 commented May 4, 2026

add the missing reverse PartialEq<Cow<'_, [U]>> impls for Vec<T, A>, &[T], and &mut [T], essentially mirroring the existing forwards in library/alloc/src/vec/partial_eq.rs

partially addresses #152830. The VecDeque half of that issue is being handled separately by #152972, so there is no overlap with this PR

also fyi: verified locally with ./x test library/alloctests --stage 1 and the new test_partial_eq_cow_symmetric test passes alongside the existing alloc test suite

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 4, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 4, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 7 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-04-14/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/too_generic_eval_ice.current/too_generic_eval_ice.current.stderr`
diff of stderr:

30    |
31    = help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
32    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<Cow<'_, [U]>>`
33              `&[T]` implements `PartialEq<Vec<U, A>>`
34              `&[T]` implements `PartialEq<[U; N]>`
35              `&[u8; N]` implements `PartialEq<ByteStr>`

36              `&[u8; N]` implements `PartialEq<ByteString>`
37              `&[u8]` implements `PartialEq<ByteStr>`
38              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
+            and 13 others
42 
43 error: aborting due to 4 previous errors
44 


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/too_generic_eval_ice.rs`

error in revision `current`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/too_generic_eval_ice.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "current" "--check-cfg" "cfg(test,FALSE,current,next)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/consts/too_generic_eval_ice.current" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:13
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |             ^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:9
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |         ^^^^^^^^^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:30
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |                              ^^
   |
   = note: this may fail depending on what value the parameter takes

error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
##[error]  --> /checkout/tests/ui/consts/too_generic_eval_ice.rs:11:30
   |
LL |         [5; Self::HOST_SIZE] == [6; 0]
   |                              ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
   |
   = help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<Cow<'_, [U]>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
           and 13 others

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
---
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/macros/assert-ne-no-invalid-help-issue-146204/assert-ne-no-invalid-help-issue-146204.stderr`
diff of stderr:

6    |
7    = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
8    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<Cow<'_, [U]>>`
9              `&[T]` implements `PartialEq<Vec<U, A>>`
10              `&[T]` implements `PartialEq<[U; N]>`
11              `&[u8; N]` implements `PartialEq<ByteStr>`

12              `&[u8; N]` implements `PartialEq<ByteString>`
13              `&[u8]` implements `PartialEq<ByteStr>`
14              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
+            and 13 others
18 
19 error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
20   --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:19:5

24    |
25    = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
26    = help: the following other types implement trait `PartialEq<Rhs>`:
+              `&[T]` implements `PartialEq<Cow<'_, [U]>>`
27              `&[T]` implements `PartialEq<Vec<U, A>>`
28              `&[T]` implements `PartialEq<[U; N]>`
29              `&[u8; N]` implements `PartialEq<ByteStr>`

30              `&[u8; N]` implements `PartialEq<ByteString>`
31              `&[u8]` implements `PartialEq<ByteStr>`
32              `&[u8]` implements `PartialEq<ByteString>`
-              `&mut [T]` implements `PartialEq<Vec<U, A>>`
-              `&mut [T]` implements `PartialEq<[U; N]>`
-            and 11 others
+              `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
+            and 13 others
36 
37 error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
38   --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:5:30


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args macros/assert-ne-no-invalid-help-issue-146204.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/macros/assert-ne-no-invalid-help-issue-146204" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:16:5
   |
LL |     assert_ne!(buf, b"----");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `[u8; 4] == &[u8; 4]`
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<Cow<'_, [U]>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
           and 13 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:19:5
   |
LL |     assert_eq!(buf, b"----");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `[u8; 4] == &[u8; 4]`
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = help: the following other types implement trait `PartialEq<Rhs>`:
             `&[T]` implements `PartialEq<Cow<'_, [U]>>`
             `&[T]` implements `PartialEq<Vec<U, A>>`
             `&[T]` implements `PartialEq<[U; N]>`
             `&[u8; N]` implements `PartialEq<ByteStr>`
             `&[u8; N]` implements `PartialEq<ByteString>`
             `&[u8]` implements `PartialEq<ByteStr>`
             `&[u8]` implements `PartialEq<ByteString>`
             `&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
           and 13 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
##[error]  --> /checkout/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.rs:5:30
   |
LL |                 if *left_val == *right_val {
   |                              ^^ no implementation for `[u8; 4] == &[u8; 4]`
...
LL |     local_assert_ne!(buf, b"----");
   |     ------------------------------ in this macro invocation
   |
   = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]`
   = note: this error originates in the macro `local_assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing here
   |
LL |                 if *left_val == **right_val {
   |                                 +

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants