Skip to content

Commit c966ab8

Browse files
committed
constify comparison traits on arrays
1 parent f7717a2 commit c966ab8

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
@@ -402,7 +402,8 @@ where
402402

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

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

0 commit comments

Comments
 (0)