diff --git a/library/core/src/any.rs b/library/core/src/any.rs index c0fb0d993c3ed..9d298512c132a 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -662,8 +662,8 @@ impl dyn Any + Send + Sync { /// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth /// noting that the hashes and ordering will vary between Rust releases. Beware /// of relying on them inside of your code! -#[derive(Clone, Copy, Debug, Hash, Eq)] -#[derive_const(PartialEq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, Hash)] +#[derive_const(PartialEq, Eq, PartialOrd, Ord)] #[stable(feature = "rust1", since = "1.0.0")] pub struct TypeId { t: u64, diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index f290e5baf9dd3..122ff616c1149 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -279,7 +279,8 @@ pub macro PartialEq($item:item) { #[doc(alias = "!=")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Eq"] -pub trait Eq: PartialEq { +#[const_trait] +pub trait Eq: ~const PartialEq { // this method is used solely by #[deriving] to assert // that every component of a type implements #[deriving] // itself, the current deriving infrastructure means doing this @@ -329,8 +330,8 @@ pub struct AssertParamIsEq { /// let result = 2.cmp(&1); /// assert_eq!(Ordering::Greater, result); /// ``` -#[derive(Clone, Copy, Eq, Debug, Hash)] -#[derive_const(PartialOrd, Ord, PartialEq)] +#[derive(Clone, Copy, Debug, Hash)] +#[derive_const(PartialOrd, Eq, Ord, PartialEq)] #[stable(feature = "rust1", since = "1.0.0")] #[repr(i8)] pub enum Ordering { @@ -594,11 +595,25 @@ impl Ordering { /// v.sort_by_key(|&num| (num > 3, Reverse(num))); /// assert_eq!(v, vec![3, 2, 1, 6, 5, 4]); /// ``` -#[derive(PartialEq, Eq, Debug, Copy, Default, Hash)] +#[derive(Debug, Copy, Default, Hash)] +#[cfg_attr(not(bootstrap), derive_const(PartialEq, Eq))] #[stable(feature = "reverse_cmp_key", since = "1.19.0")] #[repr(transparent)] pub struct Reverse(#[stable(feature = "reverse_cmp_key", since = "1.19.0")] pub T); +#[cfg(bootstrap)] +#[stable(feature = "reverse_cmp_key", since = "1.19.0")] +#[rustc_const_unstable(feature = "const_cmp", issue = "92391")] +impl const PartialEq for Reverse { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } +} +#[cfg(bootstrap)] +#[stable(feature = "reverse_cmp_key", since = "1.19.0")] +#[rustc_const_unstable(feature = "const_cmp", issue = "92391")] +impl const Eq for Reverse {} + #[stable(feature = "reverse_cmp_key", since = "1.19.0")] #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] impl const PartialOrd for Reverse { @@ -760,7 +775,7 @@ impl Clone for Reverse { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Ord"] #[const_trait] -pub trait Ord: Eq + PartialOrd { +pub trait Ord: ~const Eq + ~const PartialOrd { /// This method returns an [`Ordering`] between `self` and `other`. /// /// By convention, `self.cmp(&other)` returns the ordering matching the expression @@ -1032,7 +1047,7 @@ pub macro Ord($item:item) { )] #[const_trait] #[rustc_diagnostic_item = "PartialOrd"] -pub trait PartialOrd: PartialEq { +pub trait PartialOrd: ~const PartialEq { /// This method returns an ordering between `self` and `other` values if one exists. /// /// # Examples @@ -1331,7 +1346,8 @@ mod impls { macro_rules! eq_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Eq for $t {} + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Eq for $t {} )*) } @@ -1455,7 +1471,8 @@ mod impls { } #[unstable(feature = "never_type", issue = "35121")] - impl Eq for ! {} + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Eq for ! {} #[unstable(feature = "never_type", issue = "35121")] #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] @@ -1491,9 +1508,10 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl PartialOrd<&B> for &A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const PartialOrd<&B> for &A where - A: PartialOrd, + A: ~const PartialOrd, { #[inline] fn partial_cmp(&self, other: &&B) -> Option { @@ -1517,9 +1535,10 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl Ord for &A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Ord for &A where - A: Ord, + A: ~const Ord, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -1527,14 +1546,16 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl Eq for &A where A: Eq {} + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Eq for &A where A: ~const Eq {} // &mut pointers #[stable(feature = "rust1", since = "1.0.0")] - impl PartialEq<&mut B> for &mut A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const PartialEq<&mut B> for &mut A where - A: PartialEq, + A: ~const PartialEq, { #[inline] fn eq(&self, other: &&mut B) -> bool { @@ -1546,9 +1567,10 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl PartialOrd<&mut B> for &mut A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const PartialOrd<&mut B> for &mut A where - A: PartialOrd, + A: ~const PartialOrd, { #[inline] fn partial_cmp(&self, other: &&mut B) -> Option { @@ -1572,9 +1594,10 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl Ord for &mut A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Ord for &mut A where - A: Ord, + A: ~const Ord, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -1582,12 +1605,14 @@ mod impls { } } #[stable(feature = "rust1", since = "1.0.0")] - impl Eq for &mut A where A: Eq {} + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const Eq for &mut A where A: ~const Eq {} #[stable(feature = "rust1", since = "1.0.0")] - impl PartialEq<&mut B> for &A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const PartialEq<&mut B> for &A where - A: PartialEq, + A: ~const PartialEq, { #[inline] fn eq(&self, other: &&mut B) -> bool { @@ -1600,9 +1625,10 @@ mod impls { } #[stable(feature = "rust1", since = "1.0.0")] - impl PartialEq<&B> for &mut A + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl const PartialEq<&B> for &mut A where - A: PartialEq, + A: ~const PartialEq, { #[inline] fn eq(&self, other: &&B) -> bool { diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 2123147c7e44c..99d8a76cfe689 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -9,8 +9,8 @@ use crate::{cmp, fmt, hash, mem, num}; /// Note that particularly large alignments, while representable in this type, /// are likely not to be supported by actual allocators and linkers. #[unstable(feature = "ptr_alignment_type", issue = "102070")] -#[derive(Copy, Clone, Eq)] -#[derive_const(PartialEq)] +#[derive(Copy, Clone)] +#[derive_const(PartialEq, Eq)] #[repr(transparent)] pub struct Alignment(AlignmentEnum); diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 28275798f751e..a4b6f4f94548f 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -41,7 +41,8 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ #[stable(feature = "rust1", since = "1.0.0")] - impl<$($T: Eq),+> Eq for ($($T,)+) + #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] + impl<$($T: ~const Eq),+> const Eq for ($($T,)+) where last_type!($($T,)+): ?Sized {} @@ -51,7 +52,7 @@ macro_rules! tuple_impls { $($T)+ @ #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cmp", issue = "92391")] - impl<$($T: ~const PartialOrd + ~const PartialEq),+> const PartialOrd for ($($T,)+) + impl<$($T: ~const PartialOrd),+> const PartialOrd for ($($T,)+) where last_type!($($T,)+): ?Sized { diff --git a/tests/ui/consts/issue-25826.stderr b/tests/ui/consts/issue-25826.stderr index 905c5ee6eb4a0..d9487f720bed0 100644 --- a/tests/ui/consts/issue-25826.stderr +++ b/tests/ui/consts/issue-25826.stderr @@ -1,11 +1,11 @@ -error[E0277]: can't compare `*const ()` with `*const ()` in const contexts +error[E0277]: can't compare `*const ()` with `_` in const contexts --> $DIR/issue-25826.rs:3:52 | LL | const A: bool = unsafe { id:: as *const () < id:: as *const () }; - | ^ no implementation for `*const () < *const ()` and `*const () > *const ()` + | ^ no implementation for `*const () < _` and `*const () > _` | - = help: the trait `~const PartialOrd` is not implemented for `*const ()` -note: the trait `PartialOrd` is implemented for `*const ()`, but that implementation is not `const` + = help: the trait `~const PartialOrd<_>` is not implemented for `*const ()` +note: the trait `PartialOrd<_>` is implemented for `*const ()`, but that implementation is not `const` --> $DIR/issue-25826.rs:3:52 | LL | const A: bool = unsafe { id:: as *const () < id:: as *const () };