From 341a5cb45080996eed84bc4966b4eccdc21266ee Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sat, 13 Sep 2025 08:51:04 -0400 Subject: [PATCH 1/3] constify basic Clone impls --- library/core/src/clone.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index 7f2a40f753fa6..06d2c93cc698f 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -575,7 +575,8 @@ mod impls { ($($t:ty)*) => { $( #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for $t { + #[rustc_const_unstable(feature = "const_clone", issue = "142757")] + impl const Clone for $t { #[inline(always)] fn clone(&self) -> Self { *self @@ -593,7 +594,8 @@ mod impls { } #[unstable(feature = "never_type", issue = "35121")] - impl Clone for ! { + #[rustc_const_unstable(feature = "const_clone", issue = "142757")] + impl const Clone for ! { #[inline] fn clone(&self) -> Self { *self @@ -601,7 +603,8 @@ mod impls { } #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for *const T { + #[rustc_const_unstable(feature = "const_clone", issue = "142757")] + impl const Clone for *const T { #[inline(always)] fn clone(&self) -> Self { *self @@ -609,7 +612,8 @@ mod impls { } #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for *mut T { + #[rustc_const_unstable(feature = "const_clone", issue = "142757")] + impl const Clone for *mut T { #[inline(always)] fn clone(&self) -> Self { *self @@ -618,7 +622,8 @@ mod impls { /// Shared references can be cloned, but mutable references *cannot*! #[stable(feature = "rust1", since = "1.0.0")] - impl Clone for &T { + #[rustc_const_unstable(feature = "const_clone", issue = "142757")] + impl const Clone for &T { #[inline(always)] #[rustc_diagnostic_item = "noop_method_clone"] fn clone(&self) -> Self { From 7eb8f0064f548e240c7f22471e14d8c23cb78b5f Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sat, 13 Sep 2025 08:51:28 -0400 Subject: [PATCH 2/3] constify Default on Nanoseconds --- library/core/src/num/niche_types.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/core/src/num/niche_types.rs b/library/core/src/num/niche_types.rs index 610d9d8cf92e0..9ac0eb72bdcbc 100644 --- a/library/core/src/num/niche_types.rs +++ b/library/core/src/num/niche_types.rs @@ -112,7 +112,8 @@ impl Nanoseconds { pub const ZERO: Self = unsafe { Nanoseconds::new_unchecked(0) }; } -impl Default for Nanoseconds { +#[rustc_const_unstable(feature = "const_default", issue = "143894")] +impl const Default for Nanoseconds { #[inline] fn default() -> Self { Self::ZERO From 168ccea4d1e3ec5c191688309cb3ac8cdc05b2f4 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Sat, 13 Sep 2025 08:20:20 -0400 Subject: [PATCH 3/3] constify comparison traits on many simple types This consists mostly of derive changes or simple impl changes. --- library/core/src/alloc/layout.rs | 6 ++++-- library/core/src/char/mod.rs | 3 ++- library/core/src/fmt/mod.rs | 15 ++++++++++----- library/core/src/intrinsics/mod.rs | 3 ++- library/core/src/marker.rs | 15 ++++++++++----- library/core/src/mem/manually_drop.rs | 3 ++- library/core/src/mem/transmutability.rs | 3 ++- library/core/src/num/error.rs | 9 ++++++--- library/core/src/num/niche_types.rs | 12 ++++++++---- library/core/src/num/saturating.rs | 3 ++- library/core/src/num/wrapping.rs | 3 ++- library/core/src/ops/coroutine.rs | 3 ++- library/core/src/ops/index_range.rs | 3 ++- library/core/src/ops/range.rs | 21 ++++++++++++++------- library/core/src/ptr/alignment.rs | 18 ++++++++++++------ library/core/src/str/error.rs | 6 ++++-- library/core/src/str/lossy.rs | 3 ++- library/core/src/str/pattern.rs | 6 ++++-- library/core/src/sync/atomic.rs | 3 ++- library/core/src/task/poll.rs | 3 ++- library/core/src/time.rs | 9 ++++++--- 21 files changed, 100 insertions(+), 50 deletions(-) diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index cd5fd77f86597..4d5e342d5fde4 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -35,7 +35,8 @@ const fn size_align() -> (usize, usize) { /// like this are met, use specific allocators with looser /// requirements, or use the more lenient `Allocator` interface.) #[stable(feature = "alloc_layout", since = "1.28.0")] -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq)] #[lang = "alloc_layout"] pub struct Layout { // size of the requested block of memory, measured in bytes. @@ -545,7 +546,8 @@ pub type LayoutErr = LayoutError; /// do not satisfy its documented constraints. #[stable(feature = "alloc_layout_error", since = "1.50.0")] #[non_exhaustive] -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub struct LayoutError; #[stable(feature = "alloc_layout", since = "1.28.0")] diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index 82a3f6f916be3..8d4e587bc0e71 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -591,7 +591,8 @@ impl fmt::Display for CaseMappingIter { /// The error type returned when a checked char conversion fails. #[stable(feature = "u8_from_char", since = "1.59.0")] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy)] +#[derive_const(Clone, PartialEq, Eq)] pub struct TryFromCharError(pub(crate) ()); #[stable(feature = "u8_from_char", since = "1.59.0")] diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index b6de892530892..a3cea11e7b4cc 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -21,7 +21,8 @@ mod rt; #[stable(feature = "fmt_flags_align", since = "1.28.0")] #[rustc_diagnostic_item = "Alignment"] /// Possible alignments returned by `Formatter::align` -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub enum Alignment { #[stable(feature = "fmt_flags_align", since = "1.28.0")] /// Indication that contents should be left-aligned. @@ -103,7 +104,8 @@ pub type Result = result::Result<(), Error>; /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct Error; /// A trait for writing or formatting into Unicode-accepting buffers or streams. @@ -255,7 +257,8 @@ impl Write for &mut W { } /// The signedness of a [`Formatter`] (or of a [`FormattingOptions`]). -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] #[unstable(feature = "formatting_options", issue = "118117")] pub enum Sign { /// Represents the `+` flag. @@ -266,7 +269,8 @@ pub enum Sign { /// Specifies whether the [`Debug`] trait should use lower-/upper-case /// hexadecimal or normal integers. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] #[unstable(feature = "formatting_options", issue = "118117")] pub enum DebugAsHex { /// Use lower-case hexadecimal integers for the `Debug` trait (like [the `x?` type](../../std/fmt/index.html#formatting-traits)). @@ -279,7 +283,8 @@ pub enum DebugAsHex { /// /// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait. /// It is mainly used to construct `Formatter` instances. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] #[unstable(feature = "formatting_options", issue = "118117")] pub struct FormattingOptions { /// Flags, with the following bit fields: diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index bffffbc29c1eb..5dbbcfe81bac2 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -71,7 +71,8 @@ use crate::sync::atomic::{self, AtomicBool, AtomicI32, AtomicIsize, AtomicU32, O /// A type for atomic ordering parameters for intrinsics. This is a separate type from /// `atomic::Ordering` so that we can make it `ConstParamTy` and fix the values used here without a /// risk of leaking that to stable code. -#[derive(Debug, ConstParamTy, PartialEq, Eq)] +#[derive(Debug, ConstParamTy)] +#[derive_const(PartialEq, Eq)] pub enum AtomicOrdering { // These values must match the compiler's `AtomicOrdering` defined in // `rustc_middle/src/ty/consts/int.rs`! diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 1c100312a9a33..2d9091bd387c5 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -828,24 +828,28 @@ impl Hash for PhantomData { } #[stable(feature = "rust1", since = "1.0.0")] -impl cmp::PartialEq for PhantomData { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::PartialEq for PhantomData { fn eq(&self, _other: &PhantomData) -> bool { true } } #[stable(feature = "rust1", since = "1.0.0")] -impl cmp::Eq for PhantomData {} +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::Eq for PhantomData {} #[stable(feature = "rust1", since = "1.0.0")] -impl cmp::PartialOrd for PhantomData { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::PartialOrd for PhantomData { fn partial_cmp(&self, _other: &PhantomData) -> Option { Option::Some(cmp::Ordering::Equal) } } #[stable(feature = "rust1", since = "1.0.0")] -impl cmp::Ord for PhantomData { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::Ord for PhantomData { fn cmp(&self, _other: &PhantomData) -> cmp::Ordering { cmp::Ordering::Equal } @@ -1021,7 +1025,8 @@ pub auto trait Unpin {} // marker in your struct acts as if you wrapped the entire struct in an `UnsafePinned`. This type // will likely eventually be deprecated, and all new code should be using `UnsafePinned` instead. #[stable(feature = "pin", since = "1.33.0")] -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Debug, Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct PhantomPinned; #[stable(feature = "pin", since = "1.33.0")] diff --git a/library/core/src/mem/manually_drop.rs b/library/core/src/mem/manually_drop.rs index 8868f05f1b98f..715844796bfaa 100644 --- a/library/core/src/mem/manually_drop.rs +++ b/library/core/src/mem/manually_drop.rs @@ -151,7 +151,8 @@ use crate::ptr; /// [`MaybeUninit`]: crate::mem::MaybeUninit #[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] #[repr(transparent)] #[rustc_pub_transparent] pub struct ManuallyDrop { diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index f36cb8cddb837..cbfe21715168a 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -147,7 +147,8 @@ where /// `true`, the onus of the safety proof belongs to the programmer. #[unstable(feature = "transmutability", issue = "99571")] #[lang = "transmute_opts"] -#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub struct Assume { /// When `false`, [`TransmuteFrom`] is not implemented for transmutations /// that might violate the alignment requirements of references; e.g.: diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 8a353dc0fbe99..269b4ad7fac64 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -6,7 +6,8 @@ use crate::fmt; /// The error type returned when a checked integral type conversion fails. #[stable(feature = "try_from", since = "1.34.0")] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy)] +#[derive_const(Clone, PartialEq, Eq)] pub struct TryFromIntError(pub(crate) ()); #[stable(feature = "try_from", since = "1.34.0")] @@ -60,7 +61,8 @@ impl const From for TryFromIntError { /// println!("Failed conversion to i32: {e}"); /// } /// ``` -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] pub struct ParseIntError { pub(super) kind: IntErrorKind, @@ -78,7 +80,8 @@ pub struct ParseIntError { /// # } /// ``` #[stable(feature = "int_error_matching", since = "1.55.0")] -#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)] +#[derive(Debug, Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq)] #[non_exhaustive] pub enum IntErrorKind { /// Value being parsed is empty. diff --git a/library/core/src/num/niche_types.rs b/library/core/src/num/niche_types.rs index 9ac0eb72bdcbc..5c856eaf46506 100644 --- a/library/core/src/num/niche_types.rs +++ b/library/core/src/num/niche_types.rs @@ -14,7 +14,8 @@ macro_rules! define_valid_range_type { $(#[$m:meta])* $vis:vis struct $name:ident($int:ident as $uint:ident in $low:literal..=$high:literal); )+) => {$( - #[derive(Clone, Copy, Eq)] + #[derive(Copy)] + #[derive_const(Clone, Eq)] #[repr(transparent)] #[rustc_layout_scalar_valid_range_start($low)] #[rustc_layout_scalar_valid_range_end($high)] @@ -67,21 +68,24 @@ macro_rules! define_valid_range_type { // by . impl StructuralPartialEq for $name {} - impl PartialEq for $name { + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl const PartialEq for $name { #[inline] fn eq(&self, other: &Self) -> bool { self.as_inner() == other.as_inner() } } - impl Ord for $name { + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl const Ord for $name { #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&self.as_inner(), &other.as_inner()) } } - impl PartialOrd for $name { + #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] + impl const PartialOrd for $name { #[inline] fn partial_cmp(&self, other: &Self) -> Option { Some(Ord::cmp(self, other)) diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 365a82a57e0b9..984b7b7c9fcf9 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -32,7 +32,8 @@ use crate::ops::{ /// assert_eq!(u32::MAX, (max + one).0); /// ``` #[stable(feature = "saturating_int_impl", since = "1.74.0")] -#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] #[repr(transparent)] #[rustc_diagnostic_item = "Saturating"] pub struct Saturating(#[stable(feature = "saturating_int_impl", since = "1.74.0")] pub T); diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index 881fe615f800f..2db7a8caaadb1 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -37,7 +37,8 @@ use crate::ops::{ /// /// `Wrapping` is guaranteed to have the same layout and ABI as `T`. #[stable(feature = "rust1", since = "1.0.0")] -#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] #[repr(transparent)] #[rustc_diagnostic_item = "Wrapping"] pub struct Wrapping(#[stable(feature = "rust1", since = "1.0.0")] pub T); diff --git a/library/core/src/ops/coroutine.rs b/library/core/src/ops/coroutine.rs index c7d596d74c383..f8f214499461c 100644 --- a/library/core/src/ops/coroutine.rs +++ b/library/core/src/ops/coroutine.rs @@ -5,7 +5,8 @@ use crate::pin::Pin; /// This enum is returned from the `Coroutine::resume` method and indicates the /// possible return values of a coroutine. Currently this corresponds to either /// a suspension point (`Yielded`) or a termination point (`Complete`). -#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord)] #[lang = "coroutine_state"] #[unstable(feature = "coroutine_trait", issue = "43122")] pub enum CoroutineState { diff --git a/library/core/src/ops/index_range.rs b/library/core/src/ops/index_range.rs index 507fa9460bea6..c3335ccecc830 100644 --- a/library/core/src/ops/index_range.rs +++ b/library/core/src/ops/index_range.rs @@ -9,7 +9,8 @@ use crate::ub_checks; /// /// (Normal `Range` code needs to handle degenerate ranges like `10..0`, /// which takes extra checks compared to only handling the canonical form.) -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub(crate) struct IndexRange { start: usize, end: usize, diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 58a9431bd845d..e2b15673f1359 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -38,7 +38,8 @@ use crate::hash::Hash; /// [slicing index]: crate::slice::SliceIndex #[lang = "RangeFull"] #[doc(alias = "..")] -#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq, Default)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFull; @@ -75,7 +76,8 @@ impl fmt::Debug for RangeFull { /// ``` #[lang = "Range"] #[doc(alias = "..")] -#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186 +#[derive(Hash)] // not Copy -- see #27186 +#[derive_const(Clone, PartialEq, Eq, Default)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Range { /// The lower bound of the range (inclusive). @@ -184,7 +186,8 @@ impl> Range { /// ``` #[lang = "RangeFrom"] #[doc(alias = "..")] -#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186 +#[derive(Hash)] // not Copy -- see #27186 +#[derive_const(Clone, PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFrom { /// The lower bound of the range (inclusive). @@ -266,7 +269,8 @@ impl> RangeFrom { /// [slicing index]: crate::slice::SliceIndex #[lang = "RangeTo"] #[doc(alias = "..")] -#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeTo { /// The upper bound of the range (exclusive). @@ -340,7 +344,8 @@ impl> RangeTo { /// ``` #[lang = "RangeInclusive"] #[doc(alias = "..=")] -#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186 +#[derive(Hash)] // not Copy -- see #27186 +#[derive_const(Clone, PartialEq, Eq)] #[stable(feature = "inclusive_range", since = "1.26.0")] pub struct RangeInclusive { // Note that the fields here are not public to allow changing the @@ -587,7 +592,8 @@ impl> RangeInclusive { /// [slicing index]: crate::slice::SliceIndex #[lang = "RangeToInclusive"] #[doc(alias = "..=")] -#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq)] #[stable(feature = "inclusive_range", since = "1.26.0")] pub struct RangeToInclusive { /// The upper bound of the range (inclusive) @@ -668,7 +674,8 @@ impl> RangeToInclusive { /// /// [`BTreeMap::range`]: ../../std/collections/btree_map/struct.BTreeMap.html#method.range #[stable(feature = "collections_bound", since = "1.17.0")] -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq)] pub enum Bound { /// An inclusive bound. #[stable(feature = "collections_bound", since = "1.17.0")] diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index bc7d3a1de7151..de911f4a6cdf9 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -10,7 +10,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, PartialEq, Eq)] +#[derive(Copy)] +#[derive_const(Clone, PartialEq, Eq)] #[repr(transparent)] pub struct Alignment(AlignmentEnum); @@ -211,7 +212,8 @@ impl const From for usize { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl cmp::Ord for Alignment { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::Ord for Alignment { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { self.as_nonzero().get().cmp(&other.as_nonzero().get()) @@ -219,7 +221,8 @@ impl cmp::Ord for Alignment { } #[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl cmp::PartialOrd for Alignment { +#[rustc_const_unstable(feature = "const_cmp", issue = "143800")] +impl const cmp::PartialOrd for Alignment { #[inline] fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) @@ -244,7 +247,8 @@ impl const Default for Alignment { } #[cfg(target_pointer_width = "16")] -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy)] +#[derive_const(Clone, PartialEq, Eq)] #[repr(usize)] enum AlignmentEnum { _Align1Shl0 = 1 << 0, @@ -266,7 +270,8 @@ enum AlignmentEnum { } #[cfg(target_pointer_width = "32")] -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy)] +#[derive_const(Clone, PartialEq, Eq)] #[repr(usize)] enum AlignmentEnum { _Align1Shl0 = 1 << 0, @@ -304,7 +309,8 @@ enum AlignmentEnum { } #[cfg(target_pointer_width = "64")] -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy)] +#[derive_const(Clone, PartialEq, Eq)] #[repr(usize)] enum AlignmentEnum { _Align1Shl0 = 1 << 0, diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index 1677c849ae4bf..974c0513a8a11 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -42,7 +42,8 @@ use crate::fmt; /// } /// } /// ``` -#[derive(Copy, Eq, PartialEq, Clone, Debug)] +#[derive(Copy, Debug)] +#[derive_const(Clone, Eq, PartialEq)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Utf8Error { pub(super) valid_up_to: usize, @@ -129,7 +130,8 @@ impl Error for Utf8Error {} /// An error returned when parsing a `bool` using [`from_str`] fails /// /// [`from_str`]: super::FromStr::from_str -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] #[non_exhaustive] #[stable(feature = "rust1", since = "1.0.0")] pub struct ParseBoolError; diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 8d4210c80827d..24cbd1e1977f8 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -67,7 +67,8 @@ impl [u8] { /// assert_eq!(b"\xF1\x80", chunk.invalid()); /// ``` #[stable(feature = "utf8_chunks", since = "1.79.0")] -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub struct Utf8Chunk<'a> { valid: &'a str, invalid: &'a [u8], diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index e116b13838323..581654f272190 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -170,7 +170,8 @@ pub trait Pattern: Sized { /// Result of calling [`Pattern::as_utf8_pattern()`]. /// Can be used for inspecting the contents of a [`Pattern`] in cases /// where the underlying representation can be represented as UTF-8. -#[derive(Copy, Clone, Eq, PartialEq, Debug)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub enum Utf8Pattern<'a> { /// Type returned by String and str types. StringPattern(&'a [u8]), @@ -181,7 +182,8 @@ pub enum Utf8Pattern<'a> { // Searcher /// Result of calling [`Searcher::next()`] or [`ReverseSearcher::next_back()`]. -#[derive(Copy, Clone, Eq, PartialEq, Debug)] +#[derive(Copy, Debug)] +#[derive_const(Clone, PartialEq, Eq)] pub enum SearchStep { /// Expresses that a match of the pattern has been found at /// `haystack[a..b]`. diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 1b4a54b1b7a78..c180bfc495c4a 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -433,7 +433,8 @@ unsafe impl Sync for AtomicPtr {} /// /// [nomicon]: ../../../nomicon/atomics.html #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq)] #[non_exhaustive] #[rustc_diagnostic_item = "Ordering"] pub enum Ordering { diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 380abac0ae95f..f0c810dcb1f72 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -8,7 +8,8 @@ use crate::ops::{self, ControlFlow}; /// /// This is returned by [`Future::poll`](core::future::Future::poll). #[must_use = "this `Poll` may be a `Pending` variant, which should be handled"] -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Copy, Debug, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord)] #[lang = "Poll"] #[stable(feature = "futures_api", since = "1.36.0")] pub enum Poll { diff --git a/library/core/src/time.rs b/library/core/src/time.rs index d205bc376f125..13706fa7e5001 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -76,7 +76,8 @@ const DAYS_PER_WEEK: u64 = 7; /// compatibility, you may wish to format `Duration` objects yourself or use a /// crate to do so. #[stable(feature = "duration", since = "1.3.0")] -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Copy, Hash)] +#[derive_const(Clone, PartialEq, Eq, PartialOrd, Ord, Default)] #[rustc_diagnostic_item = "Duration"] pub struct Duration { secs: u64, @@ -1475,7 +1476,8 @@ impl fmt::Debug for Duration { /// println!("Failed conversion to Duration: {e}"); /// } /// ``` -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] +#[derive_const(PartialEq, Eq)] #[stable(feature = "duration_checked_float", since = "1.66.0")] pub struct TryFromFloatSecsError { kind: TryFromFloatSecsErrorKind, @@ -1496,7 +1498,8 @@ impl fmt::Display for TryFromFloatSecsError { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug)] +#[derive_const(Clone, PartialEq, Eq)] enum TryFromFloatSecsErrorKind { // Value is negative. Negative,