Skip to content

Commit 1cc1f90

Browse files
committed
constify comparison traits on arrays
1 parent c1cf740 commit 1cc1f90

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
@@ -394,7 +394,8 @@ where
394394

395395
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
396396
#[stable(feature = "rust1", since = "1.0.0")]
397-
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
397+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
398+
impl<T: [const] PartialOrd, const N: usize> const PartialOrd for [T; N] {
398399
#[inline]
399400
fn partial_cmp(&self, other: &[T; N]) -> Option<Ordering> {
400401
PartialOrd::partial_cmp(&&self[..], &&other[..])
@@ -419,7 +420,8 @@ impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
419420

420421
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
421422
#[stable(feature = "rust1", since = "1.0.0")]
422-
impl<T: Ord, const N: usize> Ord for [T; N] {
423+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
424+
impl<T: [const] Ord, const N: usize> const Ord for [T; N] {
423425
#[inline]
424426
fn cmp(&self, other: &[T; N]) -> Ordering {
425427
Ord::cmp(&&self[..], &&other[..])

0 commit comments

Comments
 (0)