diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/arc.rs | 61 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 59 |
3 files changed, 63 insertions, 58 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 4aba567fa1c..d0a51e320cc 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -592,6 +592,31 @@ impl<T: ?Sized> Drop for Arc<T> { } } +impl<T> Weak<T> { + /// Constructs a new `Weak<T>` without an accompanying instance of T. + /// + /// This allocates memory for T, but does not initialize it. Calling + /// Weak<T>::upgrade() on the return value always gives None. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Weak; + /// + /// let empty: Weak<i64> = Weak::new(); + /// ``` + #[stable(feature = "downgraded_weak", since = "1.10.0")] + pub fn new() -> Weak<T> { + unsafe { + Weak { ptr: Shared::new(Box::into_raw(box ArcInner { + strong: atomic::AtomicUsize::new(0), + weak: atomic::AtomicUsize::new(1), + data: uninitialized(), + }))} + } + } +} + impl<T: ?Sized> Weak<T> { /// Upgrades a weak reference to a strong reference. /// @@ -682,6 +707,13 @@ impl<T: ?Sized> Clone for Weak<T> { } } +#[stable(feature = "downgraded_weak", since = "1.10.0")] +impl<T> Default for Weak<T> { + fn default() -> Weak<T> { + Weak::new() + } +} + #[stable(feature = "arc_weak", since = "1.4.0")] impl<T: ?Sized> Drop for Weak<T> { /// Drops the `Weak<T>`. @@ -907,35 +939,6 @@ impl<T> From<T> for Arc<T> { } } -impl<T> Weak<T> { - /// Constructs a new `Weak<T>` without an accompanying instance of T. - /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak<T>::upgrade() on the return value always gives None. - /// - /// # Examples - /// - /// ``` - /// #![feature(downgraded_weak)] - /// - /// use std::sync::Weak; - /// - /// let empty: Weak<i64> = Weak::new(); - /// ``` - #[unstable(feature = "downgraded_weak", - reason = "recently added", - issue = "30425")] - pub fn new() -> Weak<T> { - unsafe { - Weak { ptr: Shared::new(Box::into_raw(box ArcInner { - strong: atomic::AtomicUsize::new(0), - weak: atomic::AtomicUsize::new(1), - data: uninitialized(), - }))} - } - } -} - #[cfg(test)] mod tests { use std::clone::Clone; diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index c2dad9a1ae4..0293d5402c4 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -90,7 +90,6 @@ #![feature(unique)] #![feature(unsafe_no_drop_flag, filling_drop)] #![feature(unsize)] -#![feature(extended_compare_and_swap)] #![cfg_attr(not(test), feature(raw, fn_traits, placement_new_protocol))] #![cfg_attr(test, feature(test, box_heap))] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index c2f0a961327..b92f5af05e3 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -720,6 +720,33 @@ impl<T: ?Sized> !marker::Sync for Weak<T> {} #[unstable(feature = "coerce_unsized", issue = "27732")] impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {} +impl<T> Weak<T> { + /// Constructs a new `Weak<T>` without an accompanying instance of T. + /// + /// This allocates memory for T, but does not initialize it. Calling + /// Weak<T>::upgrade() on the return value always gives None. + /// + /// # Examples + /// + /// ``` + /// use std::rc::Weak; + /// + /// let empty: Weak<i64> = Weak::new(); + /// ``` + #[stable(feature = "downgraded_weak", since = "1.10.0")] + pub fn new() -> Weak<T> { + unsafe { + Weak { + ptr: Shared::new(Box::into_raw(box RcBox { + strong: Cell::new(0), + weak: Cell::new(1), + value: uninitialized(), + })), + } + } + } +} + impl<T: ?Sized> Weak<T> { /// Upgrades a weak reference to a strong reference. /// @@ -823,34 +850,10 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> { } } -impl<T> Weak<T> { - /// Constructs a new `Weak<T>` without an accompanying instance of T. - /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak<T>::upgrade() on the return value always gives None. - /// - /// # Examples - /// - /// ``` - /// #![feature(downgraded_weak)] - /// - /// use std::rc::Weak; - /// - /// let empty: Weak<i64> = Weak::new(); - /// ``` - #[unstable(feature = "downgraded_weak", - reason = "recently added", - issue="30425")] - pub fn new() -> Weak<T> { - unsafe { - Weak { - ptr: Shared::new(Box::into_raw(box RcBox { - strong: Cell::new(0), - weak: Cell::new(1), - value: uninitialized(), - })), - } - } +#[stable(feature = "downgraded_weak", since = "1.10.0")] +impl<T> Default for Weak<T> { + fn default() -> Weak<T> { + Weak::new() } } |
