Skip to content

Commit a4e8de3

Browse files
committed
constify comparison traits on arrays
1 parent d438dc9 commit a4e8de3

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

library/core/src/array/equality.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::cmp::BytewiseEq;
22

33
#[stable(feature = "rust1", since = "1.0.0")]
4-
impl<T, U, const N: usize> PartialEq<[U; N]> for [T; N]
4+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
5+
impl<T, U, const N: usize> const PartialEq<[U; N]> for [T; N]
56
where
6-
T: PartialEq<U>,
7+
T: [const] PartialEq<U>,
78
{
89
#[inline]
910
fn eq(&self, other: &[U; N]) -> bool {
@@ -122,14 +123,17 @@ where
122123
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
123124

124125
#[stable(feature = "rust1", since = "1.0.0")]
125-
impl<T: Eq, const N: usize> Eq for [T; N] {}
126+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
127+
impl<T: [const] Eq, const N: usize> const Eq for [T; N] {}
126128

127-
trait SpecArrayEq<Other, const N: usize>: Sized {
129+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
130+
const trait SpecArrayEq<Other, const N: usize>: Sized {
128131
fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool;
129132
fn spec_ne(a: &[Self; N], b: &[Other; N]) -> bool;
130133
}
131134

132-
impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
135+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
136+
impl<T: [const] PartialEq<Other>, Other, const N: usize> const SpecArrayEq<Other, N> for T {
133137
default fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool {
134138
a[..] == b[..]
135139
}
@@ -138,7 +142,8 @@ impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
138142
}
139143
}
140144

141-
impl<T: BytewiseEq<U>, U, const N: usize> SpecArrayEq<U, N> for T {
145+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
146+
impl<T: [const] BytewiseEq<U>, U, const N: usize> const SpecArrayEq<U, N> for T {
142147
fn spec_eq(a: &[T; N], b: &[U; N]) -> bool {
143148
// SAFETY: Arrays are compared element-wise, and don't add any padding
144149
// between elements, so when the elements are `BytewiseEq`, we can

library/core/src/array/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ where
403403

404404
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
405405
#[stable(feature = "rust1", since = "1.0.0")]
406-
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
406+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
407+
impl<T: [const] PartialOrd, const N: usize> const PartialOrd for [T; N] {
407408
#[inline]
408409
fn partial_cmp(&self, other: &[T; N]) -> Option<Ordering> {
409410
PartialOrd::partial_cmp(&&self[..], &&other[..])
@@ -428,7 +429,8 @@ impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
428429

429430
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
430431
#[stable(feature = "rust1", since = "1.0.0")]
431-
impl<T: Ord, const N: usize> Ord for [T; N] {
432+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
433+
impl<T: [const] Ord, const N: usize> const Ord for [T; N] {
432434
#[inline]
433435
fn cmp(&self, other: &[T; N]) -> Ordering {
434436
Ord::cmp(&&self[..], &&other[..])

0 commit comments

Comments
 (0)