@@ -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,13 @@ 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
+ let mut idx = 0 ;
123
+ while idx < self . len ( ) {
119
124
// bound checks are optimized away
120
125
if self [ idx] != other[ idx] {
121
126
return false ;
122
127
}
128
+ idx += 1 ;
123
129
}
124
130
125
131
true
@@ -128,9 +134,10 @@ where
128
134
129
135
// When each element can be compared byte-wise, we can compare all the bytes
130
136
// from the whole size in one call to the intrinsics.
131
- impl < A , B > SlicePartialEq < B > for [ A ]
137
+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
138
+ impl < A , B > const SlicePartialEq < B > for [ A ]
132
139
where
133
- A : BytewiseEq < B > ,
140
+ A : ~ const BytewiseEq < B > ,
134
141
{
135
142
fn equal ( & self , other : & [ B ] ) -> bool {
136
143
if self . len ( ) != other. len ( ) {
0 commit comments