Rollup merge of #152275 - scottmcm:range-range-inclusive, r=Mark-Simulacrum
Stop having two different alignment constants Now that there's a `<T as SizedTypeProperties>::ALIGNMENT` constant, `Alignment::of` can use that instead of an inline constant, like how `Layout::new` uses the constant from `SizedTypeProperties`.
This commit is contained in:
commit
9f778b4341
8 changed files with 14 additions and 11 deletions
|
|
@ -284,9 +284,10 @@ pub unsafe trait GlobalAlloc {
|
|||
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
// SAFETY: the caller must ensure that the `new_size` does not overflow.
|
||||
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid.
|
||||
let new_layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) };
|
||||
let alignment = layout.alignment();
|
||||
// SAFETY: the caller must ensure that the `new_size` does not overflow
|
||||
// when rounded up to the next multiple of `alignment`.
|
||||
let new_layout = unsafe { Layout::from_size_alignment_unchecked(new_size, alignment) };
|
||||
// SAFETY: the caller must ensure that `new_layout` is greater than zero.
|
||||
let new_ptr = unsafe { self.alloc(new_layout) };
|
||||
if !new_ptr.is_null() {
|
||||
|
|
|
|||
|
|
@ -1260,7 +1260,10 @@ pub trait SizedTypeProperties: Sized {
|
|||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
|
||||
const ALIGNMENT: Alignment = Alignment::of::<Self>();
|
||||
const ALIGNMENT: Alignment = {
|
||||
// This can't panic since type alignment is always a power of two.
|
||||
Alignment::new(Self::ALIGN).unwrap()
|
||||
};
|
||||
|
||||
/// `true` if this type requires no storage.
|
||||
/// `false` if its [size](size_of) is greater than zero.
|
||||
|
|
|
|||
|
|
@ -52,8 +52,7 @@ impl Alignment {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn of<T>() -> Self {
|
||||
// This can't actually panic since type alignment is always a power of two.
|
||||
const { Alignment::new(align_of::<T>()).unwrap() }
|
||||
<T as mem::SizedTypeProperties>::ALIGNMENT
|
||||
}
|
||||
|
||||
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
|
||||
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
|
||||
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
|
||||
+ _6 = const {0x1 as *const [bool; 0]};
|
||||
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
|
||||
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
|
||||
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
|
||||
+ _6 = const {0x1 as *const [bool; 0]};
|
||||
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
|
||||
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
|
||||
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
|
||||
+ _6 = const {0x1 as *const [bool; 0]};
|
||||
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
|
||||
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
|
||||
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
|
||||
+ _6 = const {0x1 as *const [bool; 0]};
|
||||
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
- _3 = const std::ptr::Alignment::of::<u8>::{constant#0};
|
||||
- _3 = const <u8 as std::mem::SizedTypeProperties>::ALIGNMENT;
|
||||
- _2 = copy _3 as *mut u8 (Transmute);
|
||||
+ _3 = const std::ptr::Alignment {{ _inner_repr_trick: std::ptr::alignment::AlignmentEnum::_Align1Shl0 }};
|
||||
+ _2 = const {0x1 as *mut u8};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue