mirror of
https://github.com/rust-lang/rust
synced 2024-11-05 20:45:15 +00:00
Use <T, U>
for array/slice equality impl
s
Makes the trait implementation documentation for arrays and slices appear more consistent.
This commit is contained in:
parent
cdd4ff8d81
commit
3f3a153056
3 changed files with 42 additions and 42 deletions
|
@ -2,36 +2,36 @@
|
||||||
use crate::convert::TryInto;
|
use crate::convert::TryInto;
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
A: PartialEq<B>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &[B; N]) -> bool {
|
fn eq(&self, other: &[U; N]) -> bool {
|
||||||
SpecArrayEq::spec_eq(self, other)
|
SpecArrayEq::spec_eq(self, other)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &[B; N]) -> bool {
|
fn ne(&self, other: &[U; N]) -> bool {
|
||||||
SpecArrayEq::spec_ne(self, other)
|
SpecArrayEq::spec_ne(self, other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
A: PartialEq<B>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &[B]) -> bool {
|
fn eq(&self, other: &[U]) -> bool {
|
||||||
let b: Result<&[B; N], _> = other.try_into();
|
let b: Result<&[U; N], _> = other.try_into();
|
||||||
match b {
|
match b {
|
||||||
Ok(b) => *self == *b,
|
Ok(b) => *self == *b,
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &[B]) -> bool {
|
fn ne(&self, other: &[U]) -> bool {
|
||||||
let b: Result<&[B; N], _> = other.try_into();
|
let b: Result<&[U; N], _> = other.try_into();
|
||||||
match b {
|
match b {
|
||||||
Ok(b) => *self != *b,
|
Ok(b) => *self != *b,
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
|
@ -40,21 +40,21 @@ fn ne(&self, other: &[B]) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
B: PartialEq<A>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
fn eq(&self, other: &[U; N]) -> bool {
|
||||||
let b: Result<&[B; N], _> = self.try_into();
|
let b: Result<&[T; N], _> = self.try_into();
|
||||||
match b {
|
match b {
|
||||||
Ok(b) => *b == *other,
|
Ok(b) => *b == *other,
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
fn ne(&self, other: &[U; N]) -> bool {
|
||||||
let b: Result<&[B; N], _> = self.try_into();
|
let b: Result<&[T; N], _> = self.try_into();
|
||||||
match b {
|
match b {
|
||||||
Ok(b) => *b != *other,
|
Ok(b) => *b != *other,
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
|
@ -63,61 +63,61 @@ fn ne(&self, other: &[B]) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
A: PartialEq<B>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &&[B]) -> bool {
|
fn eq(&self, other: &&[U]) -> bool {
|
||||||
*self == **other
|
*self == **other
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &&[B]) -> bool {
|
fn ne(&self, other: &&[U]) -> bool {
|
||||||
*self != **other
|
*self != **other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
B: PartialEq<A>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
fn eq(&self, other: &[U; N]) -> bool {
|
||||||
**self == *other
|
**self == *other
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
fn ne(&self, other: &[U; N]) -> bool {
|
||||||
**self != *other
|
**self != *other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
A: PartialEq<B>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &&mut [B]) -> bool {
|
fn eq(&self, other: &&mut [U]) -> bool {
|
||||||
*self == **other
|
*self == **other
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &&mut [B]) -> bool {
|
fn ne(&self, other: &&mut [U]) -> bool {
|
||||||
*self != **other
|
*self != **other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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
|
where
|
||||||
B: PartialEq<A>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &[A; N]) -> bool {
|
fn eq(&self, other: &[U; N]) -> bool {
|
||||||
**self == *other
|
**self == *other
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ne(&self, other: &[A; N]) -> bool {
|
fn ne(&self, other: &[U; N]) -> bool {
|
||||||
**self != *other
|
**self != *other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,15 @@
|
||||||
use super::memchr;
|
use super::memchr;
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<A, B> PartialEq<[B]> for [A]
|
impl<T, U> PartialEq<[U]> for [T]
|
||||||
where
|
where
|
||||||
A: PartialEq<B>,
|
T: PartialEq<U>,
|
||||||
{
|
{
|
||||||
fn eq(&self, other: &[B]) -> bool {
|
fn eq(&self, other: &[U]) -> bool {
|
||||||
SlicePartialEq::equal(self, other)
|
SlicePartialEq::equal(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ne(&self, other: &[B]) -> bool {
|
fn ne(&self, other: &[U]) -> bool {
|
||||||
SlicePartialEq::not_equal(self, other)
|
SlicePartialEq::not_equal(self, other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
|
||||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
= help: the following other types implement trait `PartialEq<Rhs>`:
|
||||||
<[A; N] as PartialEq<[B; N]>>
|
<[T; N] as PartialEq<[U; N]>>
|
||||||
<[A; N] as PartialEq<[B]>>
|
<[T; N] as PartialEq<[U]>>
|
||||||
<[A; N] as PartialEq<&[B]>>
|
<[T; N] as PartialEq<&[U]>>
|
||||||
<[A; N] as PartialEq<&mut [B]>>
|
<[T; N] as PartialEq<&mut [U]>>
|
||||||
<[T] as PartialEq<Vec<U, A>>>
|
<[T] as PartialEq<Vec<U, A>>>
|
||||||
<[A] as PartialEq<[B]>>
|
<[T] as PartialEq<[U; N]>>
|
||||||
<[B] as PartialEq<[A; N]>>
|
<[T] as PartialEq<[U]>>
|
||||||
<&[T] as PartialEq<Vec<U, A>>>
|
<&[T] as PartialEq<Vec<U, A>>>
|
||||||
and 3 others
|
and 3 others
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue