From 9361fa7983cf80184ea6fd6b4e223bcaee35a2b3 Mon Sep 17 00:00:00 2001 From: fallofpheonix Date: Mon, 25 May 2026 05:07:41 +0530 Subject: [PATCH] Implement missing `PartialEq` between `Vec` and `[T; N]` This PR adds the missing `PartialEq` implementations between `Vec` and `[U; N]`, including symmetric and reference variants. --- library/alloc/src/vec/partial_eq.rs | 8 ++++---- library/alloctests/tests/vec.rs | 12 ++++++++++++ tests/ui/consts/too_generic_eval_ice.current.stderr | 6 +++--- .../assert-ne-no-invalid-help-issue-146204.stderr | 12 ++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index 204e5678a69d6..e0834bad5acf3 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -34,13 +34,13 @@ __impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "ru __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec, [U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] } __impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec, &[U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec, &mut [U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_array_for_vec", since = "CURRENT_RUSTC_VERSION")] } +__impl_slice_eq1! { const, [A: Allocator, const N: usize] [T; N], Vec, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_array_for_vec", since = "CURRENT_RUSTC_VERSION")] } +__impl_slice_eq1! { const, [A: Allocator, const N: usize] &[T; N], Vec, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_array_for_vec", since = "CURRENT_RUSTC_VERSION")] } +__impl_slice_eq1! { const, [A: Allocator, const N: usize] &mut [T; N], Vec, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_array_for_vec", since = "CURRENT_RUSTC_VERSION")] } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? -//__impl_slice_eq1! { [const N: usize] Vec, &mut [B; N], } -//__impl_slice_eq1! { [const N: usize] [A; N], Vec, } -//__impl_slice_eq1! { [const N: usize] &[A; N], Vec, } -//__impl_slice_eq1! { [const N: usize] &mut [A; N], Vec, } //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], } //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], } //__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], } diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs index d85d2e44cd2ba..64d82c995d66d 100644 --- a/library/alloctests/tests/vec.rs +++ b/library/alloctests/tests/vec.rs @@ -2790,3 +2790,15 @@ fn const_make_global_empty_or_zst_regression() { assert_eq!(ZST_SLICE, &[(), (), ()]); } + +#[test] +fn test_vec_partial_eq_array() { + let x = vec![1, 2, 3]; + let mut y = [1, 2, 3]; + assert_eq!(x, y); + assert_eq!(y, x); + assert_eq!(x, &y); + assert_eq!(&y, x); + assert_eq!(x, &mut y); + assert_eq!(&mut y, x); +} diff --git a/tests/ui/consts/too_generic_eval_ice.current.stderr b/tests/ui/consts/too_generic_eval_ice.current.stderr index 02bcaee80154f..9a332abf95075 100644 --- a/tests/ui/consts/too_generic_eval_ice.current.stderr +++ b/tests/ui/consts/too_generic_eval_ice.current.stderr @@ -30,15 +30,15 @@ LL | [5; Self::HOST_SIZE] == [6; 0] | = help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]` = help: the following other types implement trait `PartialEq`: + `&[T; N]` implements `PartialEq>` `&[T]` implements `PartialEq>` `&[T]` implements `PartialEq<[U; N]>` `&[u8; N]` implements `PartialEq` `&[u8; N]` implements `PartialEq` `&[u8]` implements `PartialEq` `&[u8]` implements `PartialEq` - `&mut [T]` implements `PartialEq>` - `&mut [T]` implements `PartialEq<[U; N]>` - and 11 others + `&mut [T; N]` implements `PartialEq>` + and 14 others error: aborting due to 4 previous errors diff --git a/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.stderr b/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.stderr index 359deee7bee4b..8ed845d7ab549 100644 --- a/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.stderr +++ b/tests/ui/macros/assert-ne-no-invalid-help-issue-146204.stderr @@ -6,15 +6,15 @@ LL | assert_ne!(buf, b"----"); | = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]` = help: the following other types implement trait `PartialEq`: + `&[T; N]` implements `PartialEq>` `&[T]` implements `PartialEq>` `&[T]` implements `PartialEq<[U; N]>` `&[u8; N]` implements `PartialEq` `&[u8; N]` implements `PartialEq` `&[u8]` implements `PartialEq` `&[u8]` implements `PartialEq` - `&mut [T]` implements `PartialEq>` - `&mut [T]` implements `PartialEq<[U; N]>` - and 11 others + `&mut [T; N]` implements `PartialEq>` + and 14 others error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]` --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:19:5 @@ -24,15 +24,15 @@ LL | assert_eq!(buf, b"----"); | = help: the trait `PartialEq<&[u8; 4]>` is not implemented for `[u8; 4]` = help: the following other types implement trait `PartialEq`: + `&[T; N]` implements `PartialEq>` `&[T]` implements `PartialEq>` `&[T]` implements `PartialEq<[U; N]>` `&[u8; N]` implements `PartialEq` `&[u8; N]` implements `PartialEq` `&[u8]` implements `PartialEq` `&[u8]` implements `PartialEq` - `&mut [T]` implements `PartialEq>` - `&mut [T]` implements `PartialEq<[U; N]>` - and 11 others + `&mut [T; N]` implements `PartialEq>` + and 14 others error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]` --> $DIR/assert-ne-no-invalid-help-issue-146204.rs:5:30