@@ -8,9 +8,10 @@ use crate::num::NonZero;
88use crate :: ops:: ControlFlow ;
99
1010#[ 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 ]
1213where
13- T : PartialEq < U > ,
14+ T : ~ const PartialEq < U > ,
1415{
1516 fn eq ( & self , other : & [ U ] ) -> bool {
1617 SlicePartialEq :: equal ( self , other)
@@ -94,6 +95,8 @@ impl<T: PartialOrd> PartialOrd for [T] {
9495
9596#[ doc( hidden) ]
9697// intermediate trait for specialization of slice's PartialEq
98+ #[ const_trait]
99+ #[ rustc_const_unstable( feature = "const_cmp" , issue = "143800" ) ]
97100trait SlicePartialEq < B > {
98101 fn equal ( & self , other : & [ B ] ) -> bool ;
99102
@@ -103,9 +106,10 @@ trait SlicePartialEq<B> {
103106}
104107
105108// 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 ]
107111where
108- A : PartialEq < B > ,
112+ A : ~ const PartialEq < B > ,
109113{
110114 default fn equal ( & self , other : & [ B ] ) -> bool {
111115 if self . len ( ) != other. len ( ) {
@@ -115,11 +119,14 @@ where
115119 // Implemented as explicit indexing rather
116120 // than zipped iterators for performance reasons.
117121 // 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 ( ) {
119125 // bound checks are optimized away
120126 if self [ idx] != other[ idx] {
121127 return false ;
122128 }
129+ idx += 1 ;
123130 }
124131
125132 true
@@ -128,9 +135,10 @@ where
128135
129136// When each element can be compared byte-wise, we can compare all the bytes
130137// 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 ]
132140where
133- A : BytewiseEq < B > ,
141+ A : ~ const BytewiseEq < B > ,
134142{
135143 fn equal ( & self , other : & [ B ] ) -> bool {
136144 if self . len ( ) != other. len ( ) {
0 commit comments