Skip to content

Commit 3860cb1

Browse files
committed
Update with derive_const
1 parent c207dc9 commit 3860cb1

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

library/core/src/alloc/layout.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ impl Layout {
326326
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutError)?;
327327

328328
// The safe constructor is called here to enforce the isize size limit.
329-
Layout::from_size_alignment(alloc_size, self.align).map(|layout| (layout, padded_size))
329+
match Layout::from_size_alignment(alloc_size, self.align) {
330+
Ok(layout) => Ok((layout, padded_size)),
331+
Err(e) => Err(e),
332+
}
330333
}
331334

332335
/// Creates a layout describing the record for `self` followed by

library/core/src/ptr/alignment.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::{cmp, fmt, hash, mem, num};
1010
/// are likely not to be supported by actual allocators and linkers.
1111
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
1212
#[derive(Copy, Clone, Eq)]
13+
#[cfg_attr(bootstrap, derive(PartialEq))]
14+
#[cfg_attr(not(bootstrap), derive_const(PartialEq))]
1315
#[repr(transparent)]
1416
pub struct Alignment(AlignmentEnum);
1517

@@ -167,15 +169,6 @@ impl From<Alignment> for usize {
167169
}
168170
}
169171

170-
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
171-
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
172-
impl const cmp::PartialEq for Alignment {
173-
#[inline]
174-
fn eq(&self, other: &Self) -> bool {
175-
self.as_nonzero().get() == other.as_nonzero().get()
176-
}
177-
}
178-
179172
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
180173
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
181174
impl const cmp::Ord for Alignment {
@@ -209,7 +202,9 @@ type AlignmentEnum = AlignmentEnum32;
209202
#[cfg(target_pointer_width = "64")]
210203
type AlignmentEnum = AlignmentEnum64;
211204

212-
#[derive(Copy, Clone, Eq, PartialEq)]
205+
#[derive(Copy, Clone, Eq)]
206+
#[cfg_attr(bootstrap, derive(PartialEq))]
207+
#[cfg_attr(not(bootstrap), derive_const(PartialEq))]
213208
#[repr(u16)]
214209
enum AlignmentEnum16 {
215210
_Align1Shl0 = 1 << 0,
@@ -230,7 +225,9 @@ enum AlignmentEnum16 {
230225
_Align1Shl15 = 1 << 15,
231226
}
232227

233-
#[derive(Copy, Clone, Eq, PartialEq)]
228+
#[derive(Copy, Clone, Eq)]
229+
#[cfg_attr(bootstrap, derive(PartialEq))]
230+
#[cfg_attr(not(bootstrap), derive_const(PartialEq))]
234231
#[repr(u32)]
235232
enum AlignmentEnum32 {
236233
_Align1Shl0 = 1 << 0,
@@ -267,7 +264,9 @@ enum AlignmentEnum32 {
267264
_Align1Shl31 = 1 << 31,
268265
}
269266

270-
#[derive(Copy, Clone, Eq, PartialEq)]
267+
#[derive(Copy, Clone, Eq)]
268+
#[cfg_attr(bootstrap, derive(PartialEq))]
269+
#[cfg_attr(not(bootstrap), derive_const(PartialEq))]
271270
#[repr(u64)]
272271
enum AlignmentEnum64 {
273272
_Align1Shl0 = 1 << 0,

0 commit comments

Comments
 (0)