Skip to content

Commit b4c96a9

Browse files
committed
Refine [Arc/Rc]::from_raw() docs
1 parent becebf3 commit b4c96a9

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/liballoc/rc.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,24 @@ impl<T: ?Sized> Rc<T> {
570570
ptr
571571
}
572572

573-
/// Constructs an `Rc` from a raw pointer.
573+
/// Constructs an `Rc<T>` from a raw pointer.
574574
///
575-
/// The raw pointer must have been previously returned by a call to a
576-
/// [`Rc::into_raw`][into_raw] using the same `T`.
575+
/// The raw pointer must have been previously returned by a call to
576+
/// [`Rc<U>::into_raw`][into_raw] where `U` must have the same size
577+
/// and alignment as `T`. This is trivially true if `U` is `T`.
578+
/// Note that if `U` is not `T` but has the same size and alignment, this is
579+
/// basically like transmuting references of different types. See
580+
/// [`mem::transmute`][transmute] for more information on what
581+
/// restrictions apply in this case.
582+
///
583+
/// The user of `from_raw` has to make sure a specific value of `T` is only
584+
/// dropped once.
577585
///
578586
/// This function is unsafe because improper use may lead to memory unsafety,
579-
/// even if `T` is never accessed. For example, a double-free may occur if the function is
580-
/// called twice on the same raw pointer.
587+
/// even if the returned `Rc<T>` is never accessed.
581588
///
582589
/// [into_raw]: struct.Rc.html#method.into_raw
590+
/// [transmute]: ../../std/mem/fn.transmute.html
583591
///
584592
/// # Examples
585593
///

src/liballoc/sync.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -550,16 +550,24 @@ impl<T: ?Sized> Arc<T> {
550550
ptr
551551
}
552552

553-
/// Constructs an `Arc` from a raw pointer.
553+
/// Constructs an `Arc<T>` from a raw pointer.
554554
///
555-
/// The raw pointer must have been previously returned by a call to a
556-
/// [`Arc::into_raw`][into_raw], using the same `T`.
555+
/// The raw pointer must have been previously returned by a call to
556+
/// [`Arc<U>::into_raw`][into_raw] where `U` must have the same size and
557+
/// alignment as `T`. This is trivially true if `U` is `T`.
558+
/// Note that if `U` is not `T` but has the same size and alignment, this is
559+
/// basically like transmuting references of different types. See
560+
/// [`mem::transmute`][transmute] for more information on what
561+
/// restrictions apply in this case.
562+
///
563+
/// The user of `from_raw` has to make sure a specific value of `T` is only
564+
/// dropped once.
557565
///
558566
/// This function is unsafe because improper use may lead to memory unsafety,
559-
/// even if `T` is never accessed. For example, a double-free may occur if the function is
560-
/// called twice on the same raw pointer.
567+
/// even if the returned `Arc<T>` is never accessed.
561568
///
562569
/// [into_raw]: struct.Arc.html#method.into_raw
570+
/// [transmute]: ../../std/mem/fn.transmute.html
563571
///
564572
/// # Examples
565573
///

0 commit comments

Comments
 (0)