Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use <T, U> for array/slice equality impls #120384

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
Use <T, U> for array/slice equality impls
Makes the trait implementation documentation for arrays and slices appear more consistent.
wackbyte committed Jan 26, 2024
commit 3f3a153056b0d60305f5b7d676ab2d720a91fef9
64 changes: 32 additions & 32 deletions library/core/src/array/equality.rs
Original file line number Diff line number Diff line change
@@ -2,36 +2,36 @@ use crate::cmp::BytewiseEq;
use crate::convert::TryInto;

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
impl<T, U, const N: usize> PartialEq<[U; N]> for [T; N]
where
A: PartialEq<B>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &[B; N]) -> bool {
fn eq(&self, other: &[U; N]) -> bool {
SpecArrayEq::spec_eq(self, other)
}
#[inline]
fn ne(&self, other: &[B; N]) -> bool {
fn ne(&self, other: &[U; N]) -> bool {
SpecArrayEq::spec_ne(self, other)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<[B]> for [A; N]
impl<T, U, const N: usize> PartialEq<[U]> for [T; N]
where
A: PartialEq<B>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &[B]) -> bool {
let b: Result<&[B; N], _> = other.try_into();
fn eq(&self, other: &[U]) -> bool {
let b: Result<&[U; N], _> = other.try_into();
match b {
Ok(b) => *self == *b,
Err(_) => false,
}
}
#[inline]
fn ne(&self, other: &[B]) -> bool {
let b: Result<&[B; N], _> = other.try_into();
fn ne(&self, other: &[U]) -> bool {
let b: Result<&[U; N], _> = other.try_into();
match b {
Ok(b) => *self != *b,
Err(_) => true,
@@ -40,21 +40,21 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<[A; N]> for [B]
impl<T, U, const N: usize> PartialEq<[U; N]> for [T]
where
B: PartialEq<A>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &[A; N]) -> bool {
let b: Result<&[B; N], _> = self.try_into();
fn eq(&self, other: &[U; N]) -> bool {
let b: Result<&[T; N], _> = self.try_into();
match b {
Ok(b) => *b == *other,
Err(_) => false,
}
}
#[inline]
fn ne(&self, other: &[A; N]) -> bool {
let b: Result<&[B; N], _> = self.try_into();
fn ne(&self, other: &[U; N]) -> bool {
let b: Result<&[T; N], _> = self.try_into();
match b {
Ok(b) => *b != *other,
Err(_) => true,
@@ -63,61 +63,61 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<&[B]> for [A; N]
impl<T, U, const N: usize> PartialEq<&[U]> for [T; N]
where
A: PartialEq<B>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &&[B]) -> bool {
fn eq(&self, other: &&[U]) -> bool {
*self == **other
}
#[inline]
fn ne(&self, other: &&[B]) -> bool {
fn ne(&self, other: &&[U]) -> bool {
*self != **other
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<[A; N]> for &[B]
impl<T, U, const N: usize> PartialEq<[U; N]> for &[T]
where
B: PartialEq<A>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &[A; N]) -> bool {
fn eq(&self, other: &[U; N]) -> bool {
**self == *other
}
#[inline]
fn ne(&self, other: &[A; N]) -> bool {
fn ne(&self, other: &[U; N]) -> bool {
**self != *other
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]
impl<T, U, const N: usize> PartialEq<&mut [U]> for [T; N]
where
A: PartialEq<B>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &&mut [B]) -> bool {
fn eq(&self, other: &&mut [U]) -> bool {
*self == **other
}
#[inline]
fn ne(&self, other: &&mut [B]) -> bool {
fn ne(&self, other: &&mut [U]) -> bool {
*self != **other
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B, const N: usize> PartialEq<[A; N]> for &mut [B]
impl<T, U, const N: usize> PartialEq<[U; N]> for &mut [T]
where
B: PartialEq<A>,
T: PartialEq<U>,
{
#[inline]
fn eq(&self, other: &[A; N]) -> bool {
fn eq(&self, other: &[U; N]) -> bool {
**self == *other
}
#[inline]
fn ne(&self, other: &[A; N]) -> bool {
fn ne(&self, other: &[U; N]) -> bool {
**self != *other
}
}
8 changes: 4 additions & 4 deletions library/core/src/slice/cmp.rs
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ use super::from_raw_parts;
use super::memchr;

#[stable(feature = "rust1", since = "1.0.0")]
impl<A, B> PartialEq<[B]> for [A]
impl<T, U> PartialEq<[U]> for [T]
where
A: PartialEq<B>,
T: PartialEq<U>,
{
fn eq(&self, other: &[B]) -> bool {
fn eq(&self, other: &[U]) -> bool {
SlicePartialEq::equal(self, other)
}

fn ne(&self, other: &[B]) -> bool {
fn ne(&self, other: &[U]) -> bool {
SlicePartialEq::not_equal(self, other)
}
}
12 changes: 6 additions & 6 deletions tests/ui/consts/too_generic_eval_ice.stderr
Original file line number Diff line number Diff line change
@@ -22,13 +22,13 @@ 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>`:
<[A; N] as PartialEq<[B; N]>>
<[A; N] as PartialEq<[B]>>
<[A; N] as PartialEq<&[B]>>
<[A; N] as PartialEq<&mut [B]>>
<[T; N] as PartialEq<[U; N]>>
<[T; N] as PartialEq<[U]>>
<[T; N] as PartialEq<&[U]>>
<[T; N] as PartialEq<&mut [U]>>
<[T] as PartialEq<Vec<U, A>>>
<[A] as PartialEq<[B]>>
<[B] as PartialEq<[A; N]>>
<[T] as PartialEq<[U; N]>>
<[T] as PartialEq<[U]>>
<&[T] as PartialEq<Vec<U, A>>>
and 3 others

Loading