1
Fork 0

fix alloc

This commit is contained in:
Deadbeef 2023-04-16 07:21:33 +00:00
parent 63e0ddbf1d
commit 4ecbd3be52

View file

@ -576,8 +576,7 @@ impl<T, A: Allocator> Box<T, A> {
/// ///
/// This conversion does not allocate on the heap and happens in place. /// This conversion does not allocate on the heap and happens in place.
#[unstable(feature = "box_into_boxed_slice", issue = "71582")] #[unstable(feature = "box_into_boxed_slice", issue = "71582")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")] pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
let (raw, alloc) = Box::into_raw_with_allocator(boxed); let (raw, alloc) = Box::into_raw_with_allocator(boxed);
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) } unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
} }
@ -809,9 +808,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// assert_eq!(*five, 5) /// assert_eq!(*five, 5)
/// ``` /// ```
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
#[inline] #[inline]
pub const unsafe fn assume_init(self) -> Box<T, A> { pub unsafe fn assume_init(self) -> Box<T, A> {
let (raw, alloc) = Box::into_raw_with_allocator(self); let (raw, alloc) = Box::into_raw_with_allocator(self);
unsafe { Box::from_raw_in(raw as *mut T, alloc) } unsafe { Box::from_raw_in(raw as *mut T, alloc) }
} }
@ -844,9 +842,8 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// } /// }
/// ``` /// ```
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
#[inline] #[inline]
pub const fn write(mut boxed: Self, value: T) -> Box<T, A> { pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
unsafe { unsafe {
(*boxed).write(value); (*boxed).write(value);
boxed.assume_init() boxed.assume_init()
@ -1090,9 +1087,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// ///
/// [memory layout]: self#memory-layout /// [memory layout]: self#memory-layout
#[unstable(feature = "allocator_api", issue = "32838")] #[unstable(feature = "allocator_api", issue = "32838")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
#[inline] #[inline]
pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A) { pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
let (leaked, alloc) = Box::into_unique(b); let (leaked, alloc) = Box::into_unique(b);
(leaked.as_ptr(), alloc) (leaked.as_ptr(), alloc)
} }
@ -1102,10 +1098,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
issue = "none", issue = "none",
reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead" reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
)] )]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
#[inline] #[inline]
#[doc(hidden)] #[doc(hidden)]
pub const fn into_unique(b: Self) -> (Unique<T>, A) { pub fn into_unique(b: Self) -> (Unique<T>, A) {
// Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a // Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a
// raw pointer for the type system. Turning it directly into a raw pointer would not be // raw pointer for the type system. Turning it directly into a raw pointer would not be
// recognized as "releasing" the unique pointer to permit aliased raw accesses, // recognized as "releasing" the unique pointer to permit aliased raw accesses,
@ -1163,9 +1158,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// assert_eq!(*static_ref, [4, 2, 3]); /// assert_eq!(*static_ref, [4, 2, 3]);
/// ``` /// ```
#[stable(feature = "box_leak", since = "1.26.0")] #[stable(feature = "box_leak", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
#[inline] #[inline]
pub const fn leak<'a>(b: Self) -> &'a mut T pub fn leak<'a>(b: Self) -> &'a mut T
where where
A: 'a, A: 'a,
{ {