Skip to content

Commit f48dba1

Browse files
Rollup merge of rust-lang#104308 - scottmcm:no-more-validalign, r=thomcc
Remove the old `ValidAlign` name Since it looks like there won't be any reverts needed in `Layout` for rust-lang#101899 (comment), finish off this change that I'd left out of rust-lang#102072. r? ``@thomcc`` cc tracking issue rust-lang#102070
2 parents cd4b3ac + fed1053 commit f48dba1

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

library/core/src/alloc/layout.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use crate::cmp;
88
use crate::error::Error;
99
use crate::fmt;
10-
use crate::mem::{self, ValidAlign};
11-
use crate::ptr::NonNull;
10+
use crate::mem;
11+
use crate::ptr::{Alignment, NonNull};
1212

1313
// While this function is used in one place and its implementation
1414
// could be inlined, the previous attempts to do so made rustc
@@ -46,7 +46,7 @@ pub struct Layout {
4646
//
4747
// (However, we do not analogously require `align >= sizeof(void*)`,
4848
// even though that is *also* a requirement of `posix_memalign`.)
49-
align: ValidAlign,
49+
align: Alignment,
5050
}
5151

5252
impl Layout {
@@ -71,11 +71,11 @@ impl Layout {
7171
}
7272

7373
// SAFETY: just checked that align is a power of two.
74-
Layout::from_size_valid_align(size, unsafe { ValidAlign::new_unchecked(align) })
74+
Layout::from_size_alignment(size, unsafe { Alignment::new_unchecked(align) })
7575
}
7676

7777
#[inline(always)]
78-
const fn max_size_for_align(align: ValidAlign) -> usize {
78+
const fn max_size_for_align(align: Alignment) -> usize {
7979
// (power-of-two implies align != 0.)
8080

8181
// Rounded up size is:
@@ -95,7 +95,7 @@ impl Layout {
9595

9696
/// Internal helper constructor to skip revalidating alignment validity.
9797
#[inline]
98-
const fn from_size_valid_align(size: usize, align: ValidAlign) -> Result<Self, LayoutError> {
98+
const fn from_size_alignment(size: usize, align: Alignment) -> Result<Self, LayoutError> {
9999
if size > Self::max_size_for_align(align) {
100100
return Err(LayoutError);
101101
}
@@ -117,7 +117,7 @@ impl Layout {
117117
#[rustc_allow_const_fn_unstable(ptr_alignment_type)]
118118
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
119119
// SAFETY: the caller is required to uphold the preconditions.
120-
unsafe { Layout { size, align: ValidAlign::new_unchecked(align) } }
120+
unsafe { Layout { size, align: Alignment::new_unchecked(align) } }
121121
}
122122

123123
/// The minimum size in bytes for a memory block of this layout.
@@ -321,7 +321,7 @@ impl Layout {
321321
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutError)?;
322322

323323
// The safe constructor is called here to enforce the isize size limit.
324-
Layout::from_size_valid_align(alloc_size, self.align).map(|layout| (layout, padded_size))
324+
Layout::from_size_alignment(alloc_size, self.align).map(|layout| (layout, padded_size))
325325
}
326326

327327
/// Creates a layout describing the record for `self` followed by
@@ -379,7 +379,7 @@ impl Layout {
379379
let new_size = offset.checked_add(next.size()).ok_or(LayoutError)?;
380380

381381
// The safe constructor is called here to enforce the isize size limit.
382-
let layout = Layout::from_size_valid_align(new_size, new_align)?;
382+
let layout = Layout::from_size_alignment(new_size, new_align)?;
383383
Ok((layout, offset))
384384
}
385385

@@ -400,7 +400,7 @@ impl Layout {
400400
pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
401401
let size = self.size().checked_mul(n).ok_or(LayoutError)?;
402402
// The safe constructor is called here to enforce the isize size limit.
403-
Layout::from_size_valid_align(size, self.align)
403+
Layout::from_size_alignment(size, self.align)
404404
}
405405

406406
/// Creates a layout describing the record for `self` followed by
@@ -414,7 +414,7 @@ impl Layout {
414414
pub fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
415415
let new_size = self.size().checked_add(next.size()).ok_or(LayoutError)?;
416416
// The safe constructor is called here to enforce the isize size limit.
417-
Layout::from_size_valid_align(new_size, self.align)
417+
Layout::from_size_alignment(new_size, self.align)
418418
}
419419

420420
/// Creates a layout describing the record for a `[T; n]`.
@@ -425,10 +425,10 @@ impl Layout {
425425
#[inline]
426426
pub fn array<T>(n: usize) -> Result<Self, LayoutError> {
427427
// Reduce the amount of code we need to monomorphize per `T`.
428-
return inner(mem::size_of::<T>(), ValidAlign::of::<T>(), n);
428+
return inner(mem::size_of::<T>(), Alignment::of::<T>(), n);
429429

430430
#[inline]
431-
fn inner(element_size: usize, align: ValidAlign, n: usize) -> Result<Layout, LayoutError> {
431+
fn inner(element_size: usize, align: Alignment, n: usize) -> Result<Layout, LayoutError> {
432432
// We need to check two things about the size:
433433
// - That the total size won't overflow a `usize`, and
434434
// - That the total size still fits in an `isize`.
@@ -443,7 +443,7 @@ impl Layout {
443443

444444
// SAFETY: We just checked above that the `array_size` will not
445445
// exceed `isize::MAX` even when rounded up to the alignment.
446-
// And `ValidAlign` guarantees it's a power of two.
446+
// And `Alignment` guarantees it's a power of two.
447447
unsafe { Ok(Layout::from_size_align_unchecked(array_size, align.as_usize())) }
448448
}
449449
}

library/core/src/mem/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ mod maybe_uninit;
2121
#[stable(feature = "maybe_uninit", since = "1.36.0")]
2222
pub use maybe_uninit::MaybeUninit;
2323

24-
// FIXME: This is left here for now to avoid complications around pending reverts.
25-
// Once <https://github.com/rust-lang/rust/issues/101899> is fully resolved,
26-
// this should be removed and the references in `alloc::Layout` updated.
27-
pub(crate) use ptr::Alignment as ValidAlign;
28-
2924
mod transmutability;
3025
#[unstable(feature = "transmutability", issue = "99571")]
3126
pub use transmutability::{Assume, BikeshedIntrinsicFrom};

0 commit comments

Comments
 (0)