diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-12-31 08:43:30 +0000 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2020-12-31 08:43:30 +0000 |
| commit | 589aa8e29c8b21a450ea6a78a387f6c0ac060fa4 (patch) | |
| tree | 2618f556a7cd5a3d198f3cdd1a6235efb45cf402 /library/alloc/src | |
| parent | bb15fa1da0501324783d901ddb7d9d7e1ba53080 (diff) | |
| download | rust-589aa8e29c8b21a450ea6a78a387f6c0ac060fa4.tar.gz rust-589aa8e29c8b21a450ea6a78a387f6c0ac060fa4.zip | |
Reuse Box::try_new_*_in() in Box::new_*_in()
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/boxed.rs | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index eb00d1a8b47..4391176c8be 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -387,8 +387,7 @@ impl<T, A: Allocator> Box<T, A> { // #[unstable(feature = "new_uninit", issue = "63291")] pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> { let layout = Layout::new::<mem::MaybeUninit<T>>(); - let ptr = alloc.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout)).cast(); - unsafe { Box::from_raw_in(ptr.as_ptr(), alloc) } + Box::try_new_uninit_in(alloc).unwrap_or_else(|_| handle_alloc_error(layout)) } /// Constructs a new box with uninitialized contents in the provided allocator, @@ -445,9 +444,7 @@ impl<T, A: Allocator> Box<T, A> { // #[unstable(feature = "new_uninit", issue = "63291")] pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> { let layout = Layout::new::<mem::MaybeUninit<T>>(); - let ptr = - alloc.allocate_zeroed(layout).unwrap_or_else(|_| handle_alloc_error(layout)).cast(); - unsafe { Box::from_raw_in(ptr.as_ptr(), alloc) } + Box::try_new_zeroed_in(alloc).unwrap_or_else(|_| handle_alloc_error(layout)) } /// Constructs a new `Box` with uninitialized contents, with the memory |
