Skip to content
Permalink
Browse files

fixup! sync::Weak::{as,from,into}_raw

  • Loading branch information...
vorner committed May 19, 2019
1 parent 779ec7a commit e108b25af745f992a852f656d505133937694df5
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/liballoc/sync.rs
@@ -1116,10 +1116,10 @@ impl<T> Weak<T> {
/// Consumes the `Weak<T>` and turns it into a raw pointer.
///
/// This converts the weak pointer into a raw pointer, preserving the original weak count. It
/// can be turned back into the `Weak<T>` with [`from_raw`][Weak::from_raw].
/// can be turned back into the `Weak<T>` with [`from_raw`].
///
/// The same restrictions of accessing the target of the pointer as with
/// [`as_raw`][Weak::as_raw] apply.
/// [`as_raw`] apply.
///
/// # Examples
///
@@ -1138,17 +1138,20 @@ impl<T> Weak<T> {
/// drop(unsafe { Weak::from_raw(raw) });
/// assert_eq!(0, Arc::weak_count(&strong));
/// ```
///
/// [`from_raw`]: struct.Weak.html#method.from_raw
/// [`as_raw`]: struct.Weak.html#method.as_raw
#[unstable(feature = "weak_into_raw", issue = "60728")]
pub fn into_raw(this: Self) -> *const T {
let result = Self::as_raw(&this);
mem::forget(this);
result
}

/// Converts a raw pointer previously created by [`into_raw`][Weak::into_raw] back into
/// Converts a raw pointer previously created by [`into_raw`] back into
/// `Weak<T>`.
///
/// This can be used to safely get a strong reference (by calling [`upgrade`][Weak::upgrade]
/// This can be used to safely get a strong reference (by calling [`upgrade`]
/// later) or to deallocate the weak count by dropping the `Weak<T>`.
///
/// It takes ownership of one weak count. In case a [`null`] is passed, a dangling [`Weak`] is
@@ -1184,6 +1187,10 @@ impl<T> Weak<T> {
/// ```
///
/// [`null`]: ../../std/ptr/fn.null.html
/// [`into_raw`]: struct.Weak.html#method.into_raw
/// [`upgrade`]: struct.Weak.html#method.upgrade
/// [`Weak`]: struct.Weak.html
/// [`Arc`]: struct.Arc.html
#[unstable(feature = "weak_into_raw", issue = "60728")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
if ptr.is_null() {

0 comments on commit e108b25

Please sign in to comment.
You can’t perform that action at this time.