Skip to content

Commit d45e7f6

Browse files
committed
Stabilize alloc_layout_extra
1 parent 0f0d850 commit d45e7f6

File tree

15 files changed

+57
-50
lines changed

15 files changed

+57
-50
lines changed

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-128bit-atomic-operations.patch

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ diff --git a/coretests/tests/lib.rs b/coretests/tests/lib.rs
1414
index 1e336bf..35e6f54 100644
1515
--- a/coretests/tests/lib.rs
1616
+++ b/coretests/tests/lib.rs
17-
@@ -2,5 +2,4 @@
17+
@@ -2,4 +2,3 @@
1818
// tidy-alphabetical-start
1919
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2020
#![cfg_attr(test, feature(cfg_select))]
21-
#![feature(alloc_layout_extra)]
2221
#![feature(array_ptr_get)]
2322
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
2423
index b735957..ea728b6 100644

library/alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Global {
184184
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
185185
fn alloc_impl(&self, layout: Layout, zeroed: bool) -> Result<NonNull<[u8]>, AllocError> {
186186
match layout.size() {
187-
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
187+
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling_ptr(), 0)),
188188
// SAFETY: `layout` is non-zero in size,
189189
size => unsafe {
190190
let raw_ptr = if zeroed { alloc_zeroed(layout) } else { alloc(layout) };
@@ -314,7 +314,7 @@ unsafe impl Allocator for Global {
314314
// SAFETY: conditions must be upheld by the caller
315315
0 => unsafe {
316316
self.deallocate(ptr, old_layout);
317-
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
317+
Ok(NonNull::slice_from_raw_parts(new_layout.dangling_ptr(), 0))
318318
},
319319

320320
// SAFETY: `new_size` is non-zero. Other conditions must be upheld by the caller

library/alloc/src/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<T: ?Sized + CloneToUninit, A: Allocator> Box<T, A> {
834834
}
835835
let layout = Layout::for_value::<T>(src);
836836
let (ptr, guard) = if layout.size() == 0 {
837-
(layout.dangling(), None)
837+
(layout.dangling_ptr(), None)
838838
} else {
839839
// Safety: layout is non-zero-sized
840840
let ptr = alloc.allocate(layout)?.cast();

library/alloc/src/boxed/thin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<H> WithHeader<H> {
245245
// Some paranoia checking, mostly so that the ThinBox tests are
246246
// more able to catch issues.
247247
debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST);
248-
layout.dangling()
248+
layout.dangling_ptr()
249249
} else {
250250
let ptr = alloc::alloc(layout);
251251
if ptr.is_null() {
@@ -282,7 +282,7 @@ impl<H> WithHeader<H> {
282282
// Some paranoia checking, mostly so that the ThinBox tests are
283283
// more able to catch issues.
284284
debug_assert!(value_offset == 0 && size_of::<T>() == 0 && size_of::<H>() == 0);
285-
layout.dangling()
285+
layout.dangling_ptr()
286286
} else {
287287
let ptr = alloc::alloc(layout);
288288
if ptr.is_null() {

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
// Library features:
8787
// tidy-alphabetical-start
8888
#![cfg_attr(not(no_global_oom_handling), feature(string_replace_in_place))]
89-
#![feature(alloc_layout_extra)]
9089
#![feature(allocator_api)]
9190
#![feature(array_into_iter_constructors)]
9291
#![feature(ascii_char)]

library/alloc/src/rc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
261261
#[cfg(not(no_global_oom_handling))]
262262
use core::pin::Pin;
263263
use core::pin::PinCoerceUnsized;
264-
use core::ptr::{self, NonNull, drop_in_place};
264+
use core::ptr::{self, Alignment, NonNull, drop_in_place};
265265
#[cfg(not(no_global_oom_handling))]
266266
use core::slice::from_raw_parts_mut;
267267
use core::{borrow, fmt, hint};
@@ -3847,11 +3847,11 @@ unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> usize {
38473847
// and extern types, the input safety requirement is currently enough to
38483848
// satisfy the requirements of align_of_val_raw; this is an implementation
38493849
// detail of the language that must not be relied upon outside of std.
3850-
unsafe { data_offset_align(align_of_val_raw(ptr)) }
3850+
unsafe { data_offset_align(Alignment::new_unchecked(align_of_val_raw(ptr))) }
38513851
}
38523852

38533853
#[inline]
3854-
fn data_offset_align(align: usize) -> usize {
3854+
fn data_offset_align(align: Alignment) -> usize {
38553855
let layout = Layout::new::<RcInner<()>>();
38563856
layout.size() + layout.padding_needed_for(align)
38573857
}
@@ -4478,7 +4478,7 @@ impl<T: ?Sized, A: Allocator> UniqueRcUninit<T, A> {
44784478

44794479
/// Returns the pointer to be written into to initialize the [`Rc`].
44804480
fn data_ptr(&mut self) -> *mut T {
4481-
let offset = data_offset_align(self.layout_for_value.align());
4481+
let offset = data_offset_align(self.layout_for_value.alignment());
44824482
unsafe { self.ptr.as_ptr().byte_add(offset) as *mut T }
44834483
}
44844484

library/alloc/src/sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Lega
2626
use core::ops::{Residual, Try};
2727
use core::panic::{RefUnwindSafe, UnwindSafe};
2828
use core::pin::{Pin, PinCoerceUnsized};
29-
use core::ptr::{self, NonNull};
29+
use core::ptr::{self, Alignment, NonNull};
3030
#[cfg(not(no_global_oom_handling))]
3131
use core::slice::from_raw_parts_mut;
3232
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};
@@ -4208,11 +4208,11 @@ unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> usize {
42084208
// and extern types, the input safety requirement is currently enough to
42094209
// satisfy the requirements of align_of_val_raw; this is an implementation
42104210
// detail of the language that must not be relied upon outside of std.
4211-
unsafe { data_offset_align(align_of_val_raw(ptr)) }
4211+
unsafe { data_offset_align(Alignment::new_unchecked(align_of_val_raw(ptr))) }
42124212
}
42134213

42144214
#[inline]
4215-
fn data_offset_align(align: usize) -> usize {
4215+
fn data_offset_align(align: Alignment) -> usize {
42164216
let layout = Layout::new::<ArcInner<()>>();
42174217
layout.size() + layout.padding_needed_for(align)
42184218
}
@@ -4258,7 +4258,7 @@ impl<T: ?Sized, A: Allocator> UniqueArcUninit<T, A> {
42584258

42594259
/// Returns the pointer to be written into to initialize the [`Arc`].
42604260
fn data_ptr(&mut self) -> *mut T {
4261-
let offset = data_offset_align(self.layout_for_value.align());
4261+
let offset = data_offset_align(self.layout_for_value.alignment());
42624262
unsafe { self.ptr.as_ptr().byte_add(offset) as *mut T }
42634263
}
42644264

library/alloctests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//
1515
// Library features:
1616
// tidy-alphabetical-start
17-
#![feature(alloc_layout_extra)]
1817
#![feature(allocator_api)]
1918
#![feature(array_into_iter_constructors)]
2019
#![feature(assert_matches)]

library/alloctests/tests/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct ConstAllocator;
104104
unsafe impl Allocator for ConstAllocator {
105105
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
106106
match layout.size() {
107-
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)),
107+
0 => Ok(NonNull::slice_from_raw_parts(layout.dangling_ptr(), 0)),
108108
_ => unsafe {
109109
let ptr = core::intrinsics::const_allocate(layout.size(), layout.align());
110110
Ok(NonNull::new_unchecked(ptr as *mut [u8; 0] as *mut [u8]))

library/alloctests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(allocator_api)]
2-
#![feature(alloc_layout_extra)]
32
#![feature(iter_array_chunks)]
43
#![feature(assert_matches)]
54
#![feature(wtf8_internals)]

0 commit comments

Comments
 (0)