Skip to content

Commit dd2ee24

Browse files
authored
Unrolled build for #152275
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`.
2 parents 6efa357 + 4a979d5 commit dd2ee24

8 files changed

+14
-11
lines changed

library/core/src/alloc/global.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ pub unsafe trait GlobalAlloc {
284284
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
285285
#[stable(feature = "global_alloc", since = "1.28.0")]
286286
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
287-
// SAFETY: the caller must ensure that the `new_size` does not overflow.
288-
// `layout.align()` comes from a `Layout` and is thus guaranteed to be valid.
289-
let new_layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) };
287+
let alignment = layout.alignment();
288+
// SAFETY: the caller must ensure that the `new_size` does not overflow
289+
// when rounded up to the next multiple of `alignment`.
290+
let new_layout = unsafe { Layout::from_size_alignment_unchecked(new_size, alignment) };
290291
// SAFETY: the caller must ensure that `new_layout` is greater than zero.
291292
let new_ptr = unsafe { self.alloc(new_layout) };
292293
if !new_ptr.is_null() {

library/core/src/mem/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,10 @@ pub trait SizedTypeProperties: Sized {
12601260

12611261
#[doc(hidden)]
12621262
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
1263-
const ALIGNMENT: Alignment = Alignment::of::<Self>();
1263+
const ALIGNMENT: Alignment = {
1264+
// This can't panic since type alignment is always a power of two.
1265+
Alignment::new(Self::ALIGN).unwrap()
1266+
};
12641267

12651268
/// `true` if this type requires no storage.
12661269
/// `false` if its [size](size_of) is greater than zero.

library/core/src/ptr/alignment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ impl Alignment {
5252
#[inline]
5353
#[must_use]
5454
pub const fn of<T>() -> Self {
55-
// This can't actually panic since type alignment is always a power of two.
56-
const { Alignment::new(align_of::<T>()).unwrap() }
55+
<T as mem::SizedTypeProperties>::ALIGNMENT
5756
}
5857

5958
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
StorageLive(_4);
4545
StorageLive(_5);
4646
StorageLive(_6);
47-
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
47+
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
4848
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
4949
+ _6 = const {0x1 as *const [bool; 0]};
5050
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.32bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
StorageLive(_4);
4545
StorageLive(_5);
4646
StorageLive(_6);
47-
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
47+
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
4848
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
4949
+ _6 = const {0x1 as *const [bool; 0]};
5050
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
StorageLive(_4);
4545
StorageLive(_5);
4646
StorageLive(_6);
47-
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
47+
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
4848
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
4949
+ _6 = const {0x1 as *const [bool; 0]};
5050
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
StorageLive(_4);
4545
StorageLive(_5);
4646
StorageLive(_6);
47-
- _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as *const [bool; 0] (Transmute);
47+
- _6 = const <[bool; 0] as std::mem::SizedTypeProperties>::ALIGNMENT as *const [bool; 0] (Transmute);
4848
- _5 = NonNull::<[bool; 0]> { pointer: copy _6 };
4949
+ _6 = const {0x1 as *const [bool; 0]};
5050
+ _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};

tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
StorageLive(_1);
4141
StorageLive(_2);
4242
StorageLive(_3);
43-
- _3 = const std::ptr::Alignment::of::<u8>::{constant#0};
43+
- _3 = const <u8 as std::mem::SizedTypeProperties>::ALIGNMENT;
4444
- _2 = copy _3 as *mut u8 (Transmute);
4545
+ _3 = const std::ptr::Alignment {{ _inner_repr_trick: std::ptr::alignment::AlignmentEnum::_Align1Shl0 }};
4646
+ _2 = const {0x1 as *mut u8};

0 commit comments

Comments
 (0)