Skip to content

Commit 2219744

Browse files
committed
Make several built-in types StructuralEq if their contents are StructuralEq
1 parent f6fe99c commit 2219744

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

Diff for: src/libcore/array/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::convert::{Infallible, TryFrom};
1212
use crate::fmt;
1313
use crate::hash::{self, Hash};
1414
use crate::marker::Unsize;
15+
use crate::marker::{StructuralEq, StructuralPartialEq};
1516
use crate::slice::{Iter, IterMut};
1617

1718
mod iter;
@@ -228,6 +229,14 @@ where
228229
}
229230
}
230231

232+
#[unstable(feature = "structural_match", issue = "31434")]
233+
impl<A, const N: usize> StructuralPartialEq for [A; N]
234+
where
235+
A: StructuralPartialEq,
236+
[A; N]: LengthAtMost32,
237+
{
238+
}
239+
231240
#[stable(feature = "rust1", since = "1.0.0")]
232241
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
233242
where
@@ -345,6 +354,14 @@ where
345354
// __impl_slice_eq2! { [A; $N], &'b [B; $N] }
346355
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
347356

357+
#[unstable(feature = "structural_match", issue = "31434")]
358+
impl<A, const N: usize> StructuralEq for [A; N]
359+
where
360+
A: StructuralEq,
361+
[A; N]: LengthAtMost32,
362+
{
363+
}
364+
348365
#[stable(feature = "rust1", since = "1.0.0")]
349366
impl<T: Eq, const N: usize> Eq for [T; N] where [T; N]: LengthAtMost32 {}
350367

Diff for: src/libcore/cmp.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
10431043
mod impls {
10441044
use crate::cmp::Ordering::{self, Equal, Greater, Less};
10451045
use crate::hint::unreachable_unchecked;
1046+
use crate::marker::{StructuralEq, StructuralPartialEq};
10461047

10471048
macro_rules! partial_eq_impl {
10481049
($($t:ty)*) => ($(
@@ -1209,6 +1210,9 @@ mod impls {
12091210

12101211
// & pointers
12111212

1213+
#[unstable(feature = "structural_match", issue = "31434")]
1214+
impl<A: ?Sized> StructuralPartialEq for &A where A: StructuralPartialEq {}
1215+
12121216
#[stable(feature = "rust1", since = "1.0.0")]
12131217
impl<A: ?Sized, B: ?Sized> PartialEq<&B> for &A
12141218
where
@@ -1259,11 +1263,18 @@ mod impls {
12591263
Ord::cmp(*self, *other)
12601264
}
12611265
}
1266+
1267+
#[unstable(feature = "structural_match", issue = "31434")]
1268+
impl<A: ?Sized> StructuralEq for &A where A: StructuralEq {}
1269+
12621270
#[stable(feature = "rust1", since = "1.0.0")]
12631271
impl<A: ?Sized> Eq for &A where A: Eq {}
12641272

12651273
// &mut pointers
12661274

1275+
#[unstable(feature = "structural_match", issue = "31434")]
1276+
impl<A: ?Sized> StructuralPartialEq for &mut A where A: StructuralPartialEq {}
1277+
12671278
#[stable(feature = "rust1", since = "1.0.0")]
12681279
impl<A: ?Sized, B: ?Sized> PartialEq<&mut B> for &mut A
12691280
where
@@ -1314,6 +1325,10 @@ mod impls {
13141325
Ord::cmp(*self, *other)
13151326
}
13161327
}
1328+
1329+
#[unstable(feature = "structural_match", issue = "31434")]
1330+
impl<A: ?Sized> StructuralEq for &mut A where A: StructuralEq {}
1331+
13171332
#[stable(feature = "rust1", since = "1.0.0")]
13181333
impl<A: ?Sized> Eq for &mut A where A: Eq {}
13191334

Diff for: src/libcore/slice/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::intrinsics::{assume, exact_div, is_aligned_and_not_null, unchecked_su
3030
use crate::isize;
3131
use crate::iter::*;
3232
use crate::marker::{self, Copy, Send, Sized, Sync};
33+
use crate::marker::{StructuralEq, StructuralPartialEq};
3334
use crate::mem;
3435
use crate::ops::{self, FnMut, Range};
3536
use crate::option::Option;
@@ -5752,6 +5753,9 @@ extern "C" {
57525753
fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32;
57535754
}
57545755

5756+
#[unstable(feature = "structural_match", issue = "31434")]
5757+
impl<A> StructuralPartialEq for [A] where A: StructuralPartialEq {}
5758+
57555759
#[stable(feature = "rust1", since = "1.0.0")]
57565760
impl<A, B> PartialEq<[B]> for [A]
57575761
where
@@ -5766,6 +5770,9 @@ where
57665770
}
57675771
}
57685772

5773+
#[unstable(feature = "structural_match", issue = "31434")]
5774+
impl<A> StructuralEq for [A] where A: StructuralEq {}
5775+
57695776
#[stable(feature = "rust1", since = "1.0.0")]
57705777
impl<T: Eq> Eq for [T] {}
57715778

Diff for: src/libcore/str/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,7 @@ Section: Trait implementations
17201720

17211721
mod traits {
17221722
use crate::cmp::Ordering;
1723+
use crate::marker::{StructuralEq, StructuralPartialEq};
17231724
use crate::ops;
17241725
use crate::slice::{self, SliceIndex};
17251726

@@ -1738,6 +1739,9 @@ mod traits {
17381739
}
17391740
}
17401741

1742+
#[unstable(feature = "structural_match", issue = "31434")]
1743+
impl StructuralEq for str {}
1744+
17411745
#[stable(feature = "rust1", since = "1.0.0")]
17421746
impl PartialEq for str {
17431747
#[inline]
@@ -1750,6 +1754,9 @@ mod traits {
17501754
}
17511755
}
17521756

1757+
#[unstable(feature = "structural_match", issue = "31434")]
1758+
impl StructuralPartialEq for str {}
1759+
17531760
#[stable(feature = "rust1", since = "1.0.0")]
17541761
impl Eq for str {}
17551762

Diff for: src/libcore/tuple.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::cmp::Ordering::*;
44
use crate::cmp::*;
5+
use crate::marker::{StructuralEq, StructuralPartialEq};
56

67
// macro for implementing n-ary tuple functions and operations
78
macro_rules! tuple_impls {
@@ -23,6 +24,14 @@ macro_rules! tuple_impls {
2324
}
2425
}
2526

27+
#[unstable(feature = "structural_match", issue = "31434")]
28+
impl<$($T:StructuralPartialEq),+> StructuralPartialEq for ($($T,)+)
29+
where last_type!($($T,)+): ?Sized {}
30+
31+
#[unstable(feature = "structural_match", issue = "31434")]
32+
impl<$($T:StructuralEq),+> StructuralEq for ($($T,)+)
33+
where last_type!($($T,)+): ?Sized {}
34+
2635
#[stable(feature = "rust1", since = "1.0.0")]
2736
impl<$($T:Eq),+> Eq for ($($T,)+) where last_type!($($T,)+): ?Sized {}
2837

0 commit comments

Comments
 (0)