@@ -8,9 +8,10 @@ use crate::num::NonZero;
8
8
use crate :: ops:: ControlFlow ;
9
9
10
10
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
11
- impl < T , U > PartialEq < [ U ] > for [ T ]
11
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
12
+ impl < T , U > const PartialEq < [ U ] > for [ T ]
12
13
where
13
- T : PartialEq < U > ,
14
+ T : ~ const PartialEq < U > ,
14
15
{
15
16
fn eq ( & self , other : & [ U ] ) -> bool {
16
17
SlicePartialEq :: equal ( self , other)
@@ -94,6 +95,8 @@ impl<T: PartialOrd> PartialOrd for [T] {
94
95
95
96
#[ doc( hidden) ]
96
97
// intermediate trait for specialization of slice's PartialEq
98
+ #[ const_trait]
99
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
97
100
trait SlicePartialEq < B > {
98
101
fn equal ( & self , other : & [ B ] ) -> bool ;
99
102
@@ -103,9 +106,10 @@ trait SlicePartialEq<B> {
103
106
}
104
107
105
108
// Generic slice equality
106
- impl < A , B > SlicePartialEq < B > for [ A ]
109
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
110
+ impl < A , B > const SlicePartialEq < B > for [ A ]
107
111
where
108
- A : PartialEq < B > ,
112
+ A : ~ const PartialEq < B > ,
109
113
{
110
114
default fn equal ( & self , other : & [ B ] ) -> bool {
111
115
if self . len ( ) != other. len ( ) {
@@ -115,11 +119,14 @@ where
115
119
// Implemented as explicit indexing rather
116
120
// than zipped iterators for performance reasons.
117
121
// See PR https://github.com/rust-lang/rust/pull/116846
118
- for idx in 0 ..self . len ( ) {
122
+ // FIXME(const_hack): make this a `for idx in 0..self.len()` loop.
123
+ let mut idx = 0 ;
124
+ while idx < self . len ( ) {
119
125
// bound checks are optimized away
120
126
if self [ idx] != other[ idx] {
121
127
return false ;
122
128
}
129
+ idx += 1 ;
123
130
}
124
131
125
132
true
@@ -128,9 +135,10 @@ where
128
135
129
136
// When each element can be compared byte-wise, we can compare all the bytes
130
137
// from the whole size in one call to the intrinsics.
131
- impl < A , B > SlicePartialEq < B > for [ A ]
138
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
139
+ impl < A , B > const SlicePartialEq < B > for [ A ]
132
140
where
133
- A : BytewiseEq < B > ,
141
+ A : ~ const BytewiseEq < B > ,
134
142
{
135
143
fn equal ( & self , other : & [ B ] ) -> bool {
136
144
if self . len ( ) != other. len ( ) {
0 commit comments