|
1 | 1 | use crate::convert::TryInto;
|
2 |
| -use crate::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize}; |
3 |
| -use crate::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}; |
4 | 2 |
|
5 | 3 | #[stable(feature = "rust1", since = "1.0.0")]
|
6 | 4 | impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
|
|
9 | 7 | {
|
10 | 8 | #[inline]
|
11 | 9 | fn eq(&self, other: &[B; N]) -> bool {
|
12 |
| - SpecArrayEq::spec_eq(self, other) |
| 10 | + self[..] == other[..] |
13 | 11 | }
|
14 | 12 | #[inline]
|
15 | 13 | fn ne(&self, other: &[B; N]) -> bool {
|
16 |
| - SpecArrayEq::spec_ne(self, other) |
| 14 | + self[..] != other[..] |
17 | 15 | }
|
18 | 16 | }
|
19 | 17 |
|
@@ -129,88 +127,3 @@ where
|
129 | 127 |
|
130 | 128 | #[stable(feature = "rust1", since = "1.0.0")]
|
131 | 129 | impl<T: Eq, const N: usize> Eq for [T; N] {}
|
132 |
| - |
133 |
| -trait SpecArrayEq<Other, const N: usize>: Sized { |
134 |
| - fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool; |
135 |
| - fn spec_ne(a: &[Self; N], b: &[Other; N]) -> bool; |
136 |
| -} |
137 |
| - |
138 |
| -impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T { |
139 |
| - default fn spec_eq(a: &[Self; N], b: &[Other; N]) -> bool { |
140 |
| - a[..] == b[..] |
141 |
| - } |
142 |
| - default fn spec_ne(a: &[Self; N], b: &[Other; N]) -> bool { |
143 |
| - a[..] != b[..] |
144 |
| - } |
145 |
| -} |
146 |
| - |
147 |
| -impl<T: IsRawEqComparable<U>, U, const N: usize> SpecArrayEq<U, N> for T { |
148 |
| - fn spec_eq(a: &[T; N], b: &[U; N]) -> bool { |
149 |
| - // SAFETY: This is why `IsRawEqComparable` is an `unsafe trait`. |
150 |
| - unsafe { |
151 |
| - let b = &*b.as_ptr().cast::<[T; N]>(); |
152 |
| - crate::intrinsics::raw_eq(a, b) |
153 |
| - } |
154 |
| - } |
155 |
| - fn spec_ne(a: &[T; N], b: &[U; N]) -> bool { |
156 |
| - !Self::spec_eq(a, b) |
157 |
| - } |
158 |
| -} |
159 |
| - |
160 |
| -/// `U` exists on here mostly because `min_specialization` didn't let me |
161 |
| -/// repeat the `T` type parameter in the above specialization, so instead |
162 |
| -/// the `T == U` constraint comes from the impls on this. |
163 |
| -/// # Safety |
164 |
| -/// - Neither `Self` nor `U` has any padding. |
165 |
| -/// - `Self` and `U` have the same layout. |
166 |
| -/// - `Self: PartialEq<U>` is byte-wise (this means no floats, among other things) |
167 |
| -#[rustc_specialization_trait] |
168 |
| -unsafe trait IsRawEqComparable<U>: PartialEq<U> {} |
169 |
| - |
170 |
| -macro_rules! is_raw_eq_comparable { |
171 |
| - ($($t:ty),+ $(,)?) => {$( |
172 |
| - unsafe impl IsRawEqComparable<$t> for $t {} |
173 |
| - )+}; |
174 |
| -} |
175 |
| - |
176 |
| -// SAFETY: All the ordinary integer types allow all bit patterns as distinct values |
177 |
| -is_raw_eq_comparable!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); |
178 |
| - |
179 |
| -// SAFETY: bool and char have *niches*, but no *padding*, so this is sound |
180 |
| -is_raw_eq_comparable!(bool, char); |
181 |
| - |
182 |
| -// SAFETY: Similarly, the non-zero types have a niche, but no undef, |
183 |
| -// and they compare like their underlying numeric type. |
184 |
| -is_raw_eq_comparable!( |
185 |
| - NonZeroU8, |
186 |
| - NonZeroU16, |
187 |
| - NonZeroU32, |
188 |
| - NonZeroU64, |
189 |
| - NonZeroU128, |
190 |
| - NonZeroUsize, |
191 |
| - NonZeroI8, |
192 |
| - NonZeroI16, |
193 |
| - NonZeroI32, |
194 |
| - NonZeroI64, |
195 |
| - NonZeroI128, |
196 |
| - NonZeroIsize, |
197 |
| -); |
198 |
| - |
199 |
| -// SAFETY: The NonZero types have the "null" optimization guaranteed, and thus |
200 |
| -// are also safe to equality-compare bitwise inside an `Option`. |
201 |
| -// The way `PartialOrd` is defined for `Option` means that this wouldn't work |
202 |
| -// for `<` or `>` on the signed types, but since we only do `==` it's fine. |
203 |
| -is_raw_eq_comparable!( |
204 |
| - Option<NonZeroU8>, |
205 |
| - Option<NonZeroU16>, |
206 |
| - Option<NonZeroU32>, |
207 |
| - Option<NonZeroU64>, |
208 |
| - Option<NonZeroU128>, |
209 |
| - Option<NonZeroUsize>, |
210 |
| - Option<NonZeroI8>, |
211 |
| - Option<NonZeroI16>, |
212 |
| - Option<NonZeroI32>, |
213 |
| - Option<NonZeroI64>, |
214 |
| - Option<NonZeroI128>, |
215 |
| - Option<NonZeroIsize>, |
216 |
| -); |
0 commit comments