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
20 changes: 20 additions & 0 deletions library/alloc/src/collections/vec_deque/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ macro_rules! __impl_slice_eq1 {
}
}
}

macro_rules! __impl_slice_eq2 {
([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => {
#[stable(feature = "vec_deque_partial_eq_slice", since = "1.17.0")]
impl<T, U, A: Allocator, $($vars)*> PartialEq<$rhs> for $lhs
where
T: PartialEq<U>,
$($constraints)*
{
fn eq(&self, other: &$rhs) -> bool {
if self.len() != other.len() {
return false;
}
let (oa, ob) = other.as_slices();
let (sa, sb) = self[..].split_at(oa.len());
sa == oa && sb == ob
}
}
}
}
7 changes: 7 additions & 0 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,13 @@ __impl_slice_eq1! { [const N: usize] VecDeque<T, A>, [U; N], }
__impl_slice_eq1! { [const N: usize] VecDeque<T, A>, &[U; N], }
__impl_slice_eq1! { [const N: usize] VecDeque<T, A>, &mut [U; N], }

__impl_slice_eq2! { [] Vec<T, A>, VecDeque<U, A>, }
__impl_slice_eq2! { [] &[T], VecDeque<U, A>, }
__impl_slice_eq2! { [] &mut [T], VecDeque<U, A>, }
__impl_slice_eq2! { [const N: usize] [T; N], VecDeque<U, A>, }
__impl_slice_eq2! { [const N: usize] &[T; N], VecDeque<U, A>, }
__impl_slice_eq2! { [const N: usize] &mut [T; N], VecDeque<U, A>, }

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd, A: Allocator> PartialOrd for VecDeque<T, A> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Expand Down
21 changes: 21 additions & 0 deletions library/alloctests/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,27 @@ fn test_partial_eq_array() {
assert!(d == ['a', 'b']);
}

#[test]
fn test_partial_eq_vecdeque_reverse() {
let mut d = VecDeque::with_capacity(4);
d.push_back(1);
d.push_back(2);
d.push_back(3);
d.pop_front();
d.push_back(4);

let v = vec![2, 3, 4];
let a = [2, 3, 4];
let mut b = [2, 3, 4];

assert!(v == d);
assert!(&v[..] == d);
assert!(&mut b[..] == d);
assert!(a == d);
assert!(&a == d);
assert!(&mut b == d);
}

#[test]
fn test_hash() {
let mut x = VecDeque::new();
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; N]` implements `PartialEq<VecDeque<U, A>>`
`&[T]` implements `PartialEq<Vec<U, A>>`
`&[T]` implements `PartialEq<VecDeque<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
and 16 others

error: aborting due to 4 previous errors

Expand Down
Loading