refactor Arc<T>::default
This commit is contained in:
parent
7782401c52
commit
0a963ab2da
@ -3447,13 +3447,16 @@ impl<T: Default> Default for Arc<T> {
|
|||||||
/// assert_eq!(*x, 0);
|
/// assert_eq!(*x, 0);
|
||||||
/// ```
|
/// ```
|
||||||
fn default() -> Arc<T> {
|
fn default() -> Arc<T> {
|
||||||
let x = Box::into_raw(Box::write(Box::new_uninit(), ArcInner {
|
unsafe {
|
||||||
strong: atomic::AtomicUsize::new(1),
|
Self::from_inner(
|
||||||
weak: atomic::AtomicUsize::new(1),
|
Box::leak(Box::write(Box::new_uninit(), ArcInner {
|
||||||
data: T::default(),
|
strong: atomic::AtomicUsize::new(1),
|
||||||
}));
|
weak: atomic::AtomicUsize::new(1),
|
||||||
// SAFETY: `Box::into_raw` consumes the `Box` and never returns null
|
data: T::default(),
|
||||||
unsafe { Self::from_inner(NonNull::new_unchecked(x)) }
|
}))
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user