From 6f2dcac78b536ba66912346766059e52ff5e94a6 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 12 Nov 2022 14:21:18 -0500 Subject: [PATCH] Update with derive_const --- library/core/src/alloc/layout.rs | 5 ++++- library/core/src/ptr/alignment.rs | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 2c1911c350e..bea62779bf8 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -326,7 +326,10 @@ impl Layout { let alloc_size = padded_size.checked_mul(n).ok_or(LayoutError)?; // The safe constructor is called here to enforce the isize size limit. - Layout::from_size_alignment(alloc_size, self.align).map(|layout| (layout, padded_size)) + match Layout::from_size_alignment(alloc_size, self.align) { + Ok(layout) => Ok((layout, padded_size)), + Err(e) => Err(e), + } } /// Creates a layout describing the record for `self` followed by diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index fd3e4326ac3..dea979265e6 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -10,6 +10,8 @@ use crate::{cmp, fmt, hash, mem, num}; /// are likely not to be supported by actual allocators and linkers. #[unstable(feature = "ptr_alignment_type", issue = "102070")] #[derive(Copy, Clone, Eq)] +#[cfg_attr(bootstrap, derive(PartialEq))] +#[cfg_attr(not(bootstrap), derive_const(PartialEq))] #[repr(transparent)] pub struct Alignment(AlignmentEnum); @@ -167,15 +169,6 @@ impl From for usize { } } -#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")] -#[unstable(feature = "ptr_alignment_type", issue = "102070")] -impl const cmp::PartialEq for Alignment { - #[inline] - fn eq(&self, other: &Self) -> bool { - self.as_nonzero().get() == other.as_nonzero().get() - } -} - #[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")] #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl const cmp::Ord for Alignment { @@ -209,7 +202,9 @@ type AlignmentEnum = AlignmentEnum32; #[cfg(target_pointer_width = "64")] type AlignmentEnum = AlignmentEnum64; -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq)] +#[cfg_attr(bootstrap, derive(PartialEq))] +#[cfg_attr(not(bootstrap), derive_const(PartialEq))] #[repr(u16)] enum AlignmentEnum16 { _Align1Shl0 = 1 << 0, @@ -230,7 +225,9 @@ enum AlignmentEnum16 { _Align1Shl15 = 1 << 15, } -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq)] +#[cfg_attr(bootstrap, derive(PartialEq))] +#[cfg_attr(not(bootstrap), derive_const(PartialEq))] #[repr(u32)] enum AlignmentEnum32 { _Align1Shl0 = 1 << 0, @@ -267,7 +264,9 @@ enum AlignmentEnum32 { _Align1Shl31 = 1 << 31, } -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Copy, Clone, Eq)] +#[cfg_attr(bootstrap, derive(PartialEq))] +#[cfg_attr(not(bootstrap), derive_const(PartialEq))] #[repr(u64)] enum AlignmentEnum64 { _Align1Shl0 = 1 << 0,