Skip to content

Commit d3fa9aa

Browse files
committed
Auto merge of rust-lang#116167 - RalfJung:structural-eq, r=lcnr
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust rust-lang#115893 to check for `Eq`, and rule out float matching for good. Fixes rust-lang#115881
2 parents 844c75a + cd531ab commit d3fa9aa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

core/src/marker.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub trait Unsize<T: ?Sized> {
187187
/// Required trait for constants used in pattern matches.
188188
///
189189
/// Any type that derives `PartialEq` automatically implements this trait,
190-
/// *regardless* of whether its type-parameters implement `Eq`.
190+
/// *regardless* of whether its type-parameters implement `PartialEq`.
191191
///
192192
/// If a `const` item contains some type that does not implement this trait,
193193
/// then that type either (1.) does not implement `PartialEq` (which means the
@@ -200,7 +200,7 @@ pub trait Unsize<T: ?Sized> {
200200
/// a pattern match.
201201
///
202202
/// See also the [structural match RFC][RFC1445], and [issue 63438] which
203-
/// motivated migrating from attribute-based design to this trait.
203+
/// motivated migrating from an attribute-based design to this trait.
204204
///
205205
/// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md
206206
/// [issue 63438]: https://github.com/rust-lang/rust/issues/63438
@@ -218,7 +218,7 @@ marker_impls! {
218218
isize, i8, i16, i32, i64, i128,
219219
bool,
220220
char,
221-
str /* Technically requires `[u8]: StructuralEq` */,
221+
str /* Technically requires `[u8]: StructuralPartialEq` */,
222222
(),
223223
{T, const N: usize} [T; N],
224224
{T} [T],
@@ -275,13 +275,15 @@ marker_impls! {
275275
#[unstable(feature = "structural_match", issue = "31434")]
276276
#[diagnostic::on_unimplemented(message = "the type `{Self}` does not `#[derive(Eq)]`")]
277277
#[lang = "structural_teq"]
278+
#[cfg(bootstrap)]
278279
pub trait StructuralEq {
279280
// Empty.
280281
}
281282

282283
// FIXME: Remove special cases of these types from the compiler pattern checking code and always check `T: StructuralEq` instead
283284
marker_impls! {
284285
#[unstable(feature = "structural_match", issue = "31434")]
286+
#[cfg(bootstrap)]
285287
StructuralEq for
286288
usize, u8, u16, u32, u64, u128,
287289
isize, i8, i16, i32, i64, i128,
@@ -859,6 +861,7 @@ impl<T: ?Sized> Default for PhantomData<T> {
859861
impl<T: ?Sized> StructuralPartialEq for PhantomData<T> {}
860862

861863
#[unstable(feature = "structural_match", issue = "31434")]
864+
#[cfg(bootstrap)]
862865
impl<T: ?Sized> StructuralEq for PhantomData<T> {}
863866

864867
/// Compiler-internal trait used to indicate the type of enum discriminants.
@@ -1038,6 +1041,20 @@ pub trait PointerLike {}
10381041
#[unstable(feature = "adt_const_params", issue = "95174")]
10391042
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
10401043
#[allow(multiple_supertrait_upcastable)]
1044+
#[cfg(not(bootstrap))]
1045+
pub trait ConstParamTy: StructuralPartialEq + Eq {}
1046+
1047+
/// A marker for types which can be used as types of `const` generic parameters.
1048+
///
1049+
/// These types must have a proper equivalence relation (`Eq`) and it must be automatically
1050+
/// derived (`StructuralPartialEq`). There's a hard-coded check in the compiler ensuring
1051+
/// that all fields are also `ConstParamTy`, which implies that recursively, all fields
1052+
/// are `StructuralPartialEq`.
1053+
#[lang = "const_param_ty"]
1054+
#[unstable(feature = "adt_const_params", issue = "95174")]
1055+
#[rustc_on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
1056+
#[allow(multiple_supertrait_upcastable)]
1057+
#[cfg(bootstrap)]
10411058
pub trait ConstParamTy: StructuralEq + StructuralPartialEq + Eq {}
10421059

10431060
/// Derive macro generating an impl of the trait `ConstParamTy`.

core/src/tuple.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::cmp::Ordering::{self, *};
44
use crate::marker::ConstParamTy;
5-
use crate::marker::{StructuralEq, StructuralPartialEq};
5+
use crate::marker::StructuralPartialEq;
66

77
// Recursive macro for implementing n-ary tuple functions and operations
88
//
@@ -64,7 +64,8 @@ macro_rules! tuple_impls {
6464
maybe_tuple_doc! {
6565
$($T)+ @
6666
#[unstable(feature = "structural_match", issue = "31434")]
67-
impl<$($T),+> StructuralEq for ($($T,)+)
67+
#[cfg(bootstrap)]
68+
impl<$($T),+> crate::marker::StructuralEq for ($($T,)+)
6869
{}
6970
}
7071

0 commit comments

Comments
 (0)