Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit 96d273e

Browse files
committed
Make NonZeroLayout have exactly one non-zero value
cc rust-gamedev/wg#70 (comment)
1 parent 58bedf1 commit 96d273e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/alloc/layout.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct NonZeroLayout {
4444
//
4545
// (However, we do not analogously require `align >= sizeof(void*)`,
4646
// even though that is *also* a requirement of `posix_memalign`.)
47-
align: NonZeroUsize,
47+
align: usize,
4848
}
4949

5050
impl NonZeroLayout {
@@ -71,7 +71,10 @@ impl NonZeroLayout {
7171
#[inline]
7272
#[must_use]
7373
pub const unsafe fn from_size_align_unchecked(size: NonZeroUsize, align: NonZeroUsize) -> Self {
74-
Self { size, align }
74+
Self {
75+
size,
76+
align: align.get(),
77+
}
7578
}
7679

7780
/// The minimum size in bytes for a memory block of this layout.
@@ -85,7 +88,7 @@ impl NonZeroLayout {
8588
#[inline]
8689
#[must_use]
8790
pub const fn align(&self) -> NonZeroUsize {
88-
self.align
91+
unsafe { NonZeroUsize::new_unchecked(self.align) }
8992
}
9093

9194
/// Constructs a `NonZeroLayout` suitable for holding a value of type `T`.

0 commit comments

Comments
 (0)