Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const fn size_align<T>() -> (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.
Expand Down Expand Up @@ -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")]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
15 changes: 10 additions & 5 deletions library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -593,23 +594,26 @@ 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
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> Clone for *const T {
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
impl<T: PointeeSized> const Clone for *const T {
#[inline(always)]
fn clone(&self) -> Self {
*self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> Clone for *mut T {
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
impl<T: PointeeSized> const Clone for *mut T {
#[inline(always)]
fn clone(&self) -> Self {
*self
Expand All @@ -618,7 +622,8 @@ mod impls {

/// Shared references can be cloned, but mutable references *cannot*!
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> Clone for &T {
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
impl<T: PointeeSized> const Clone for &T {
#[inline(always)]
#[rustc_diagnostic_item = "noop_method_clone"]
fn clone(&self) -> Self {
Expand Down
15 changes: 10 additions & 5 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -256,7 +258,8 @@ impl<W: Write + ?Sized> 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.
Expand All @@ -267,7 +270,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)).
Expand All @@ -280,7 +284,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:
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`!
Expand Down
15 changes: 10 additions & 5 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,24 +828,28 @@ impl<T: PointeeSized> Hash for PhantomData<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> cmp::PartialEq for PhantomData<T> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl<T: PointeeSized> const cmp::PartialEq for PhantomData<T> {
fn eq(&self, _other: &PhantomData<T>) -> bool {
true
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> cmp::Eq for PhantomData<T> {}
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl<T: PointeeSized> const cmp::Eq for PhantomData<T> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> cmp::PartialOrd for PhantomData<T> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl<T: PointeeSized> const cmp::PartialOrd for PhantomData<T> {
fn partial_cmp(&self, _other: &PhantomData<T>) -> Option<cmp::Ordering> {
Option::Some(cmp::Ordering::Equal)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> cmp::Ord for PhantomData<T> {
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl<T: PointeeSized> const cmp::Ord for PhantomData<T> {
fn cmp(&self, _other: &PhantomData<T>) -> cmp::Ordering {
cmp::Ordering::Equal
}
Expand Down Expand Up @@ -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")]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/mem/manually_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ?Sized> {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/mem/transmutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
Expand Down
9 changes: 6 additions & 3 deletions library/core/src/num/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions library/core/src/num/niche_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -67,21 +68,24 @@ macro_rules! define_valid_range_type {
// by <https://github.com/rust-lang/compiler-team/issues/807>.
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<Ordering> {
Some(Ord::cmp(self, other))
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/saturating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(#[stable(feature = "saturating_int_impl", since = "1.74.0")] pub T);
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ use crate::ops::{
///
/// `Wrapping<T>` 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<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/ops/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Y, R> {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/ops/index_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 14 additions & 7 deletions library/core/src/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Idx> {
/// The lower bound of the range (inclusive).
Expand Down Expand Up @@ -184,7 +186,8 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// ```
#[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<Idx> {
/// The lower bound of the range (inclusive).
Expand Down Expand Up @@ -266,7 +269,8 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
/// [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<Idx> {
/// The upper bound of the range (exclusive).
Expand Down Expand Up @@ -340,7 +344,8 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// ```
#[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<Idx> {
// Note that the fields here are not public to allow changing the
Expand Down Expand Up @@ -587,7 +592,8 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// [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<Idx> {
/// The upper bound of the range (inclusive)
Expand Down Expand Up @@ -668,7 +674,8 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
///
/// [`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<T> {
/// An inclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Expand Down
Loading
Loading