Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/alloc/src/vec/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ __impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[sta
__impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
#[cfg(not(no_global_oom_handling))]
__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
#[cfg(not(no_global_oom_handling))]
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, Cow<'_, [U]> where U: Clone, #[stable(feature = "partialeq_cow_for_vec_and_slice", since = "CURRENT_RUSTC_VERSION")] }
#[cfg(not(no_global_oom_handling))]
__impl_slice_eq1! { [] &[T], Cow<'_, [U]> where U: Clone, #[stable(feature = "partialeq_cow_for_vec_and_slice", since = "CURRENT_RUSTC_VERSION")] }
#[cfg(not(no_global_oom_handling))]
__impl_slice_eq1! { [] &mut [T], Cow<'_, [U]> where U: Clone, #[stable(feature = "partialeq_cow_for_vec_and_slice", since = "CURRENT_RUSTC_VERSION")] }
__impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec<T, A>, [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<T, A>, &[U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }

Expand Down
19 changes: 19 additions & 0 deletions library/alloctests/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,25 @@ fn test_from_cow() {
assert_eq!(Vec::from(Cow::Owned(owned)), vec!["owned", "(vec)"]);
}

#[test]
fn test_partial_eq_cow_symmetric() {
let v: Vec<i32> = vec![1, 2, 3];
let c: Cow<'_, [i32]> = Cow::Borrowed(&[1, 2, 3]);

assert_eq!(c, v);
assert_eq!(v, c);

let s: &[i32] = &[1, 2, 3];
assert_eq!(s, c);

let mut arr = [1, 2, 3];
let ms: &mut [i32] = &mut arr;
assert_eq!(ms, c);

let v2: Vec<i32> = vec![1, 2, 4];
assert!(v2 != c);
}

#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/too_generic_eval_ice.current.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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<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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
`&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
and 13 others

error: aborting due to 4 previous errors

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/macros/assert-ne-no-invalid-help-issue-146204.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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<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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
`&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
and 13 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
--> $DIR/assert-ne-no-invalid-help-issue-146204.rs:19:5
Expand All @@ -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<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<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
and 11 others
`&mut [T]` implements `PartialEq<Cow<'_, [U]>>`
and 13 others

error[E0277]: can't compare `[u8; 4]` with `&[u8; 4]`
--> $DIR/assert-ne-no-invalid-help-issue-146204.rs:5:30
Expand Down
Loading