Skip to content

Commit dab967a

Browse files
committed
Use alloc::Global in Box::new_uninit
1 parent 4eeb623 commit dab967a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/liballoc/boxed.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use core::ptr::{self, NonNull, Unique};
9494
use core::slice;
9595
use core::task::{Context, Poll};
9696

97-
use crate::alloc;
97+
use crate::alloc::{self, Global, Alloc};
9898
use crate::vec::Vec;
9999
use crate::raw_vec::RawVec;
100100
use crate::str::from_boxed_utf8_unchecked;
@@ -144,9 +144,11 @@ impl<T> Box<T> {
144144
#[unstable(feature = "new_uninit", issue = "0")]
145145
pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
146146
let layout = alloc::Layout::new::<mem::MaybeUninit<T>>();
147-
let ptr = unsafe { alloc::alloc(layout) };
148-
let unique = Unique::new(ptr).unwrap_or_else(|| alloc::handle_alloc_error(layout));
149-
Box(unique.cast())
147+
let ptr = unsafe {
148+
Global.alloc(layout)
149+
.unwrap_or_else(|_| alloc::handle_alloc_error(layout))
150+
};
151+
Box(ptr.cast().into())
150152
}
151153

152154
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then

0 commit comments

Comments
 (0)