We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Arc<T>::default
1 parent 7782401 commit 0a963abCopy full SHA for 0a963ab
library/alloc/src/sync.rs
@@ -3447,13 +3447,16 @@ impl<T: Default> Default for Arc<T> {
3447
/// assert_eq!(*x, 0);
3448
/// ```
3449
fn default() -> Arc<T> {
3450
- let x = Box::into_raw(Box::write(Box::new_uninit(), ArcInner {
3451
- strong: atomic::AtomicUsize::new(1),
3452
- weak: atomic::AtomicUsize::new(1),
3453
- data: T::default(),
3454
- }));
3455
- // SAFETY: `Box::into_raw` consumes the `Box` and never returns null
3456
- 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(),
+ }))
3457
+ .into(),
3458
+ )
3459
+ }
3460
}
3461
3462
0 commit comments