Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit dc46013

Browse files
committed
refactor: moved PartialEq into partial_eq
1 parent 5ac6709 commit dc46013

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ mod is_zero;
103103

104104
mod source_iter_marker;
105105

106+
mod partial_eq;
107+
106108
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
107109
///
108110
/// # Examples
@@ -2615,45 +2617,6 @@ impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec<T, A> {
26152617
}
26162618
}
26172619

2618-
macro_rules! __impl_slice_eq1 {
2619-
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
2620-
#[$stability]
2621-
impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
2622-
where
2623-
T: PartialEq<U>,
2624-
$($ty: $bound)?
2625-
{
2626-
#[inline]
2627-
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
2628-
#[inline]
2629-
fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
2630-
}
2631-
}
2632-
}
2633-
2634-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, Vec<U, A>, #[stable(feature = "rust1", since = "1.0.0")] }
2635-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] }
2636-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] }
2637-
__impl_slice_eq1! { [A: Allocator] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
2638-
__impl_slice_eq1! { [A: Allocator] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
2639-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
2640-
__impl_slice_eq1! { [A: Allocator] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
2641-
__impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2642-
__impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2643-
__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
2644-
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] }
2645-
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] }
2646-
2647-
// NOTE: some less important impls are omitted to reduce code bloat
2648-
// FIXME(Centril): Reconsider this?
2649-
//__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], }
2650-
//__impl_slice_eq1! { [const N: usize] [A; N], Vec<B>, }
2651-
//__impl_slice_eq1! { [const N: usize] &[A; N], Vec<B>, }
2652-
//__impl_slice_eq1! { [const N: usize] &mut [A; N], Vec<B>, }
2653-
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], }
2654-
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
2655-
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }
2656-
26572620
/// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison).
26582621
#[stable(feature = "rust1", since = "1.0.0")]
26592622
impl<T: PartialOrd, A: Allocator> PartialOrd for Vec<T, A> {

library/alloc/src/vec/partial_eq.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::alloc::{Allocator};
2+
use crate::borrow::Cow;
3+
4+
use super::{Vec};
5+
6+
macro_rules! __impl_slice_eq1 {
7+
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
8+
#[$stability]
9+
impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
10+
where
11+
T: PartialEq<U>,
12+
$($ty: $bound)?
13+
{
14+
#[inline]
15+
fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] }
16+
#[inline]
17+
fn ne(&self, other: &$rhs) -> bool { self[..] != other[..] }
18+
}
19+
}
20+
}
21+
22+
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, Vec<U, A>, #[stable(feature = "rust1", since = "1.0.0")] }
23+
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] }
24+
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] }
25+
__impl_slice_eq1! { [A: Allocator] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
26+
__impl_slice_eq1! { [A: Allocator] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
27+
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
28+
__impl_slice_eq1! { [A: Allocator] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
29+
__impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
30+
__impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
31+
__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
32+
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] }
33+
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] }
34+
35+
// NOTE: some less important impls are omitted to reduce code bloat
36+
// FIXME(Centril): Reconsider this?
37+
//__impl_slice_eq1! { [const N: usize] Vec<A>, &mut [B; N], }
38+
//__impl_slice_eq1! { [const N: usize] [A; N], Vec<B>, }
39+
//__impl_slice_eq1! { [const N: usize] &[A; N], Vec<B>, }
40+
//__impl_slice_eq1! { [const N: usize] &mut [A; N], Vec<B>, }
41+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, [B; N], }
42+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
43+
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }

0 commit comments

Comments
 (0)