Skip to content

Commit 7994ddf

Browse files
committed
Constify Eq, Ord, PartialOrd
1 parent 3507a74 commit 7994ddf

File tree

24 files changed

+258
-187
lines changed

24 files changed

+258
-187
lines changed

library/core/src/any.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ impl dyn Any + Send + Sync {
705705
/// std::mem::forget(fake_one_ring);
706706
/// }
707707
/// ```
708-
#[derive(Clone, Copy, Eq, PartialOrd, Ord)]
708+
#[derive(Copy, PartialOrd, Ord)]
709+
#[derive_const(Clone, Eq)]
709710
#[stable(feature = "rust1", since = "1.0.0")]
710711
#[lang = "type_id"]
711712
pub struct TypeId {

library/core/src/array/equality.rs

Lines changed: 29 additions & 17 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 {
@@ -16,9 +17,10 @@ where
1617
}
1718

1819
#[stable(feature = "rust1", since = "1.0.0")]
19-
impl<T, U, const N: usize> PartialEq<[U]> for [T; N]
20+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
21+
impl<T, U, const N: usize> const PartialEq<[U]> for [T; N]
2022
where
21-
T: PartialEq<U>,
23+
T: [const] PartialEq<U>,
2224
{
2325
#[inline]
2426
fn eq(&self, other: &[U]) -> bool {
@@ -37,9 +39,10 @@ where
3739
}
3840

3941
#[stable(feature = "rust1", since = "1.0.0")]
40-
impl<T, U, const N: usize> PartialEq<[U; N]> for [T]
42+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
43+
impl<T, U, const N: usize> const PartialEq<[U; N]> for [T]
4144
where
42-
T: PartialEq<U>,
45+
T: [const] PartialEq<U>,
4346
{
4447
#[inline]
4548
fn eq(&self, other: &[U; N]) -> bool {
@@ -58,9 +61,10 @@ where
5861
}
5962

6063
#[stable(feature = "rust1", since = "1.0.0")]
61-
impl<T, U, const N: usize> PartialEq<&[U]> for [T; N]
64+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
65+
impl<T, U, const N: usize> const PartialEq<&[U]> for [T; N]
6266
where
63-
T: PartialEq<U>,
67+
T: [const] PartialEq<U>,
6468
{
6569
#[inline]
6670
fn eq(&self, other: &&[U]) -> bool {
@@ -73,9 +77,10 @@ where
7377
}
7478

7579
#[stable(feature = "rust1", since = "1.0.0")]
76-
impl<T, U, const N: usize> PartialEq<[U; N]> for &[T]
80+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
81+
impl<T, U, const N: usize> const PartialEq<[U; N]> for &[T]
7782
where
78-
T: PartialEq<U>,
83+
T: [const] PartialEq<U>,
7984
{
8085
#[inline]
8186
fn eq(&self, other: &[U; N]) -> bool {
@@ -88,9 +93,10 @@ where
8893
}
8994

9095
#[stable(feature = "rust1", since = "1.0.0")]
91-
impl<T, U, const N: usize> PartialEq<&mut [U]> for [T; N]
96+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
97+
impl<T, U, const N: usize> const PartialEq<&mut [U]> for [T; N]
9298
where
93-
T: PartialEq<U>,
99+
T: [const] PartialEq<U>,
94100
{
95101
#[inline]
96102
fn eq(&self, other: &&mut [U]) -> bool {
@@ -103,9 +109,10 @@ where
103109
}
104110

105111
#[stable(feature = "rust1", since = "1.0.0")]
106-
impl<T, U, const N: usize> PartialEq<[U; N]> for &mut [T]
112+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
113+
impl<T, U, const N: usize> const PartialEq<[U; N]> for &mut [T]
107114
where
108-
T: PartialEq<U>,
115+
T: [const] PartialEq<U>,
109116
{
110117
#[inline]
111118
fn eq(&self, other: &[U; N]) -> bool {
@@ -122,14 +129,18 @@ where
122129
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
123130

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

135+
#[const_trait]
136+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
127137
trait SpecArrayEq<Other, const N: usize>: Sized {
128138
fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool;
129139
fn spec_ne(a: &[Self; N], b: &[Other; N]) -> bool;
130140
}
131141

132-
impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
142+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
143+
impl<T: [const] PartialEq<Other>, Other, const N: usize> const SpecArrayEq<Other, N> for T {
133144
default fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool {
134145
a[..] == b[..]
135146
}
@@ -138,7 +149,8 @@ impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
138149
}
139150
}
140151

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

library/core/src/array/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,17 @@ impl const From<Infallible> for TryFromSliceError {
206206
}
207207

208208
#[stable(feature = "rust1", since = "1.0.0")]
209-
impl<T, const N: usize> AsRef<[T]> for [T; N] {
209+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
210+
impl<T, const N: usize> const AsRef<[T]> for [T; N] {
210211
#[inline]
211212
fn as_ref(&self) -> &[T] {
212213
&self[..]
213214
}
214215
}
215216

216217
#[stable(feature = "rust1", since = "1.0.0")]
217-
impl<T, const N: usize> AsMut<[T]> for [T; N] {
218+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
219+
impl<T, const N: usize> const AsMut<[T]> for [T; N] {
218220
#[inline]
219221
fn as_mut(&mut self) -> &mut [T] {
220222
&mut self[..]
@@ -248,7 +250,8 @@ impl<T, const N: usize> BorrowMut<[T]> for [T; N] {
248250
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
249251
/// ```
250252
#[stable(feature = "try_from", since = "1.34.0")]
251-
impl<T, const N: usize> TryFrom<&[T]> for [T; N]
253+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
254+
impl<T, const N: usize> const TryFrom<&[T]> for [T; N]
252255
where
253256
T: Copy,
254257
{
@@ -273,7 +276,8 @@ where
273276
/// assert_eq!(512, u16::from_le_bytes(bytes_tail));
274277
/// ```
275278
#[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")]
276-
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]
279+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
280+
impl<T, const N: usize> const TryFrom<&mut [T]> for [T; N]
277281
where
278282
T: Copy,
279283
{
@@ -298,7 +302,8 @@ where
298302
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
299303
/// ```
300304
#[stable(feature = "try_from", since = "1.34.0")]
301-
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
305+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
306+
impl<'a, T, const N: usize> const TryFrom<&'a [T]> for &'a [T; N] {
302307
type Error = TryFromSliceError;
303308

304309
#[inline]
@@ -320,7 +325,8 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
320325
/// assert_eq!(512, u16::from_le_bytes(*bytes_tail));
321326
/// ```
322327
#[stable(feature = "try_from", since = "1.34.0")]
323-
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
328+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
329+
impl<'a, T, const N: usize> const TryFrom<&'a mut [T]> for &'a mut [T; N] {
324330
type Error = TryFromSliceError;
325331

326332
#[inline]

library/core/src/ascii/ascii_char.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ use crate::{assert_unsafe_precondition, fmt};
5454
/// [chart]: https://www.unicode.org/charts/PDF/U0000.pdf
5555
/// [NIST FIPS 1-2]: https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-1977.pdf
5656
/// [NamesList]: https://www.unicode.org/Public/15.0.0/ucd/NamesList.txt
57-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
57+
#[derive(Copy, Hash)]
58+
#[derive_const(Clone, Eq, PartialEq, Ord, PartialOrd)]
5859
#[unstable(feature = "ascii_char", issue = "110998")]
5960
#[repr(u8)]
6061
pub enum AsciiChar {

0 commit comments

Comments
 (0)