Update with derive_const

This commit is contained in:
Rune Tynan 2022-11-12 14:21:18 -05:00
parent 414e84a2f7
commit 6f2dcac78b
2 changed files with 15 additions and 13 deletions

View File

@ -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

View File

@ -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<Alignment> 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,