diff options
| author | bors <bors@rust-lang.org> | 2024-10-23 05:57:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-23 05:57:00 +0000 |
| commit | 9abfcb49002b82f46ad66ceb0b26cee8be2dc658 (patch) | |
| tree | aa8bccbfa0dd67611f41cb19546f84c19e0d2cec /library/alloc/src | |
| parent | e1f306899514ea80abc1d1c9f6a57762afb304a3 (diff) | |
| parent | b44a0fa61cafb6e9d61e4100c27e042cfe5c171a (diff) | |
| download | rust-9abfcb49002b82f46ad66ceb0b26cee8be2dc658.tar.gz rust-9abfcb49002b82f46ad66ceb0b26cee8be2dc658.zip | |
Auto merge of #132053 - matthiaskrgr:rollup-u5ds6i3, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #131707 (Run most `core::num` tests in const context too) - #132002 (abi/compatibility: also test Option-like types) - #132026 (analyse: remove unused uncanonicalized field) - #132031 (Optimize `Rc<T>::default`) - #132040 (relnotes: fix stabilizations of `assume_init`) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/rc.rs | 11 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 17 |
2 files changed, 20 insertions, 8 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index e98ae7c31ad..582d850e14b 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2312,7 +2312,16 @@ impl<T: Default> Default for Rc<T> { /// ``` #[inline] fn default() -> Rc<T> { - Rc::new(Default::default()) + unsafe { + Self::from_inner( + Box::leak(Box::write(Box::new_uninit(), RcInner { + strong: Cell::new(1), + weak: Cell::new(1), + value: T::default(), + })) + .into(), + ) + } } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index acbc325a514..13677245e98 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3447,13 +3447,16 @@ impl<T: Default> Default for Arc<T> { /// assert_eq!(*x, 0); /// ``` fn default() -> Arc<T> { - 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(), + ) + } } } |
