Skip to content

Commit 3f3a153

Browse files
committed
Use <T, U> for array/slice equality impls
Makes the trait implementation documentation for arrays and slices appear more consistent.
1 parent cdd4ff8 commit 3f3a153

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

library/core/src/array/equality.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@ use crate::cmp::BytewiseEq;
22
use crate::convert::TryInto;
33

44
#[stable(feature = "rust1", since = "1.0.0")]
5-
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
5+
impl<T, U, const N: usize> PartialEq<[U; N]> for [T; N]
66
where
7-
A: PartialEq<B>,
7+
T: PartialEq<U>,
88
{
99
#[inline]
10-
fn eq(&self, other: &[B; N]) -> bool {
10+
fn eq(&self, other: &[U; N]) -> bool {
1111
SpecArrayEq::spec_eq(self, other)
1212
}
1313
#[inline]
14-
fn ne(&self, other: &[B; N]) -> bool {
14+
fn ne(&self, other: &[U; N]) -> bool {
1515
SpecArrayEq::spec_ne(self, other)
1616
}
1717
}
1818

1919
#[stable(feature = "rust1", since = "1.0.0")]
20-
impl<A, B, const N: usize> PartialEq<[B]> for [A; N]
20+
impl<T, U, const N: usize> PartialEq<[U]> for [T; N]
2121
where
22-
A: PartialEq<B>,
22+
T: PartialEq<U>,
2323
{
2424
#[inline]
25-
fn eq(&self, other: &[B]) -> bool {
26-
let b: Result<&[B; N], _> = other.try_into();
25+
fn eq(&self, other: &[U]) -> bool {
26+
let b: Result<&[U; N], _> = other.try_into();
2727
match b {
2828
Ok(b) => *self == *b,
2929
Err(_) => false,
3030
}
3131
}
3232
#[inline]
33-
fn ne(&self, other: &[B]) -> bool {
34-
let b: Result<&[B; N], _> = other.try_into();
33+
fn ne(&self, other: &[U]) -> bool {
34+
let b: Result<&[U; N], _> = other.try_into();
3535
match b {
3636
Ok(b) => *self != *b,
3737
Err(_) => true,
@@ -40,21 +40,21 @@ where
4040
}
4141

4242
#[stable(feature = "rust1", since = "1.0.0")]
43-
impl<A, B, const N: usize> PartialEq<[A; N]> for [B]
43+
impl<T, U, const N: usize> PartialEq<[U; N]> for [T]
4444
where
45-
B: PartialEq<A>,
45+
T: PartialEq<U>,
4646
{
4747
#[inline]
48-
fn eq(&self, other: &[A; N]) -> bool {
49-
let b: Result<&[B; N], _> = self.try_into();
48+
fn eq(&self, other: &[U; N]) -> bool {
49+
let b: Result<&[T; N], _> = self.try_into();
5050
match b {
5151
Ok(b) => *b == *other,
5252
Err(_) => false,
5353
}
5454
}
5555
#[inline]
56-
fn ne(&self, other: &[A; N]) -> bool {
57-
let b: Result<&[B; N], _> = self.try_into();
56+
fn ne(&self, other: &[U; N]) -> bool {
57+
let b: Result<&[T; N], _> = self.try_into();
5858
match b {
5959
Ok(b) => *b != *other,
6060
Err(_) => true,
@@ -63,61 +63,61 @@ where
6363
}
6464

6565
#[stable(feature = "rust1", since = "1.0.0")]
66-
impl<A, B, const N: usize> PartialEq<&[B]> for [A; N]
66+
impl<T, U, const N: usize> PartialEq<&[U]> for [T; N]
6767
where
68-
A: PartialEq<B>,
68+
T: PartialEq<U>,
6969
{
7070
#[inline]
71-
fn eq(&self, other: &&[B]) -> bool {
71+
fn eq(&self, other: &&[U]) -> bool {
7272
*self == **other
7373
}
7474
#[inline]
75-
fn ne(&self, other: &&[B]) -> bool {
75+
fn ne(&self, other: &&[U]) -> bool {
7676
*self != **other
7777
}
7878
}
7979

8080
#[stable(feature = "rust1", since = "1.0.0")]
81-
impl<A, B, const N: usize> PartialEq<[A; N]> for &[B]
81+
impl<T, U, const N: usize> PartialEq<[U; N]> for &[T]
8282
where
83-
B: PartialEq<A>,
83+
T: PartialEq<U>,
8484
{
8585
#[inline]
86-
fn eq(&self, other: &[A; N]) -> bool {
86+
fn eq(&self, other: &[U; N]) -> bool {
8787
**self == *other
8888
}
8989
#[inline]
90-
fn ne(&self, other: &[A; N]) -> bool {
90+
fn ne(&self, other: &[U; N]) -> bool {
9191
**self != *other
9292
}
9393
}
9494

9595
#[stable(feature = "rust1", since = "1.0.0")]
96-
impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]
96+
impl<T, U, const N: usize> PartialEq<&mut [U]> for [T; N]
9797
where
98-
A: PartialEq<B>,
98+
T: PartialEq<U>,
9999
{
100100
#[inline]
101-
fn eq(&self, other: &&mut [B]) -> bool {
101+
fn eq(&self, other: &&mut [U]) -> bool {
102102
*self == **other
103103
}
104104
#[inline]
105-
fn ne(&self, other: &&mut [B]) -> bool {
105+
fn ne(&self, other: &&mut [U]) -> bool {
106106
*self != **other
107107
}
108108
}
109109

110110
#[stable(feature = "rust1", since = "1.0.0")]
111-
impl<A, B, const N: usize> PartialEq<[A; N]> for &mut [B]
111+
impl<T, U, const N: usize> PartialEq<[U; N]> for &mut [T]
112112
where
113-
B: PartialEq<A>,
113+
T: PartialEq<U>,
114114
{
115115
#[inline]
116-
fn eq(&self, other: &[A; N]) -> bool {
116+
fn eq(&self, other: &[U; N]) -> bool {
117117
**self == *other
118118
}
119119
#[inline]
120-
fn ne(&self, other: &[A; N]) -> bool {
120+
fn ne(&self, other: &[U; N]) -> bool {
121121
**self != *other
122122
}
123123
}

library/core/src/slice/cmp.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use super::from_raw_parts;
88
use super::memchr;
99

1010
#[stable(feature = "rust1", since = "1.0.0")]
11-
impl<A, B> PartialEq<[B]> for [A]
11+
impl<T, U> PartialEq<[U]> for [T]
1212
where
13-
A: PartialEq<B>,
13+
T: PartialEq<U>,
1414
{
15-
fn eq(&self, other: &[B]) -> bool {
15+
fn eq(&self, other: &[U]) -> bool {
1616
SlicePartialEq::equal(self, other)
1717
}
1818

19-
fn ne(&self, other: &[B]) -> bool {
19+
fn ne(&self, other: &[U]) -> bool {
2020
SlicePartialEq::not_equal(self, other)
2121
}
2222
}

tests/ui/consts/too_generic_eval_ice.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
2222
|
2323
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
2424
= help: the following other types implement trait `PartialEq<Rhs>`:
25-
<[A; N] as PartialEq<[B; N]>>
26-
<[A; N] as PartialEq<[B]>>
27-
<[A; N] as PartialEq<&[B]>>
28-
<[A; N] as PartialEq<&mut [B]>>
25+
<[T; N] as PartialEq<[U; N]>>
26+
<[T; N] as PartialEq<[U]>>
27+
<[T; N] as PartialEq<&[U]>>
28+
<[T; N] as PartialEq<&mut [U]>>
2929
<[T] as PartialEq<Vec<U, A>>>
30-
<[A] as PartialEq<[B]>>
31-
<[B] as PartialEq<[A; N]>>
30+
<[T] as PartialEq<[U; N]>>
31+
<[T] as PartialEq<[U]>>
3232
<&[T] as PartialEq<Vec<U, A>>>
3333
and 3 others
3434

0 commit comments

Comments
 (0)