Skip to content

Commit db7ac64

Browse files
Rollup merge of #144867 - scottmcm:more-as-array, r=chenyukang
Use `as_array` in PartialEq for arrays Now that `as_array` exists we might as well use it here, since it's a bit more convenient than getting the correct type out of `try_into`.
2 parents 149ee59 + eee2813 commit db7ac64

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

library/core/src/array/equality.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ where
2222
{
2323
#[inline]
2424
fn eq(&self, other: &[U]) -> bool {
25-
let b: Result<&[U; N], _> = other.try_into();
26-
match b {
27-
Ok(b) => *self == *b,
28-
Err(_) => false,
25+
match other.as_array::<N>() {
26+
Some(b) => *self == *b,
27+
None => false,
2928
}
3029
}
3130
#[inline]
3231
fn ne(&self, other: &[U]) -> bool {
33-
let b: Result<&[U; N], _> = other.try_into();
34-
match b {
35-
Ok(b) => *self != *b,
36-
Err(_) => true,
32+
match other.as_array::<N>() {
33+
Some(b) => *self != *b,
34+
None => true,
3735
}
3836
}
3937
}
@@ -45,18 +43,16 @@ where
4543
{
4644
#[inline]
4745
fn eq(&self, other: &[U; N]) -> bool {
48-
let b: Result<&[T; N], _> = self.try_into();
49-
match b {
50-
Ok(b) => *b == *other,
51-
Err(_) => false,
46+
match self.as_array::<N>() {
47+
Some(b) => *b == *other,
48+
None => false,
5249
}
5350
}
5451
#[inline]
5552
fn ne(&self, other: &[U; N]) -> bool {
56-
let b: Result<&[T; N], _> = self.try_into();
57-
match b {
58-
Ok(b) => *b != *other,
59-
Err(_) => true,
53+
match self.as_array::<N>() {
54+
Some(b) => *b != *other,
55+
None => true,
6056
}
6157
}
6258
}

0 commit comments

Comments
 (0)