7
7
use crate :: cmp;
8
8
use crate :: error:: Error ;
9
9
use crate :: fmt;
10
- use crate :: mem:: { self , ValidAlign } ;
11
- use crate :: ptr:: NonNull ;
10
+ use crate :: mem;
11
+ use crate :: ptr:: { Alignment , NonNull } ;
12
12
13
13
// While this function is used in one place and its implementation
14
14
// could be inlined, the previous attempts to do so made rustc
@@ -46,7 +46,7 @@ pub struct Layout {
46
46
//
47
47
// (However, we do not analogously require `align >= sizeof(void*)`,
48
48
// even though that is *also* a requirement of `posix_memalign`.)
49
- align : ValidAlign ,
49
+ align : Alignment ,
50
50
}
51
51
52
52
impl Layout {
@@ -71,11 +71,11 @@ impl Layout {
71
71
}
72
72
73
73
// 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) } )
75
75
}
76
76
77
77
#[ inline( always) ]
78
- const fn max_size_for_align ( align : ValidAlign ) -> usize {
78
+ const fn max_size_for_align ( align : Alignment ) -> usize {
79
79
// (power-of-two implies align != 0.)
80
80
81
81
// Rounded up size is:
@@ -95,7 +95,7 @@ impl Layout {
95
95
96
96
/// Internal helper constructor to skip revalidating alignment validity.
97
97
#[ 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 > {
99
99
if size > Self :: max_size_for_align ( align) {
100
100
return Err ( LayoutError ) ;
101
101
}
@@ -117,7 +117,7 @@ impl Layout {
117
117
#[ rustc_allow_const_fn_unstable( ptr_alignment_type) ]
118
118
pub const unsafe fn from_size_align_unchecked ( size : usize , align : usize ) -> Self {
119
119
// 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) } }
121
121
}
122
122
123
123
/// The minimum size in bytes for a memory block of this layout.
@@ -321,7 +321,7 @@ impl Layout {
321
321
let alloc_size = padded_size. checked_mul ( n) . ok_or ( LayoutError ) ?;
322
322
323
323
// 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) )
325
325
}
326
326
327
327
/// Creates a layout describing the record for `self` followed by
@@ -379,7 +379,7 @@ impl Layout {
379
379
let new_size = offset. checked_add ( next. size ( ) ) . ok_or ( LayoutError ) ?;
380
380
381
381
// 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) ?;
383
383
Ok ( ( layout, offset) )
384
384
}
385
385
@@ -400,7 +400,7 @@ impl Layout {
400
400
pub fn repeat_packed ( & self , n : usize ) -> Result < Self , LayoutError > {
401
401
let size = self . size ( ) . checked_mul ( n) . ok_or ( LayoutError ) ?;
402
402
// 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 )
404
404
}
405
405
406
406
/// Creates a layout describing the record for `self` followed by
@@ -414,7 +414,7 @@ impl Layout {
414
414
pub fn extend_packed ( & self , next : Self ) -> Result < Self , LayoutError > {
415
415
let new_size = self . size ( ) . checked_add ( next. size ( ) ) . ok_or ( LayoutError ) ?;
416
416
// 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 )
418
418
}
419
419
420
420
/// Creates a layout describing the record for a `[T; n]`.
@@ -425,10 +425,10 @@ impl Layout {
425
425
#[ inline]
426
426
pub fn array < T > ( n : usize ) -> Result < Self , LayoutError > {
427
427
// 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) ;
429
429
430
430
#[ 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 > {
432
432
// We need to check two things about the size:
433
433
// - That the total size won't overflow a `usize`, and
434
434
// - That the total size still fits in an `isize`.
@@ -443,7 +443,7 @@ impl Layout {
443
443
444
444
// SAFETY: We just checked above that the `array_size` will not
445
445
// 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.
447
447
unsafe { Ok ( Layout :: from_size_align_unchecked ( array_size, align. as_usize ( ) ) ) }
448
448
}
449
449
}
0 commit comments