diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index acbc325a51415..13677245e98c2 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3447,13 +3447,16 @@ impl Default for Arc { /// assert_eq!(*x, 0); /// ``` fn default() -> Arc { - let x = Box::into_raw(Box::write(Box::new_uninit(), ArcInner { - strong: atomic::AtomicUsize::new(1), - weak: atomic::AtomicUsize::new(1), - data: T::default(), - })); - // SAFETY: `Box::into_raw` consumes the `Box` and never returns null - unsafe { Self::from_inner(NonNull::new_unchecked(x)) } + unsafe { + Self::from_inner( + Box::leak(Box::write(Box::new_uninit(), ArcInner { + strong: atomic::AtomicUsize::new(1), + weak: atomic::AtomicUsize::new(1), + data: T::default(), + })) + .into(), + ) + } } }