Skip to content

Commit becebf3

Browse files
committed
Ammend Rc/Arc::from_raw() docs regarding unsafety
Constructing an Rc/Arc is unsafe even if the wrapped `T` is never dereferenced.
1 parent f795e8a commit becebf3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/liballoc/rc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,11 @@ impl<T: ?Sized> Rc<T> {
573573
/// Constructs an `Rc` from a raw pointer.
574574
///
575575
/// The raw pointer must have been previously returned by a call to a
576-
/// [`Rc::into_raw`][into_raw].
576+
/// [`Rc::into_raw`][into_raw] using the same `T`.
577577
///
578-
/// This function is unsafe because improper use may lead to memory problems. For example, a
579-
/// double-free may occur if the function is called twice on the same raw pointer.
578+
/// 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.
580581
///
581582
/// [into_raw]: struct.Rc.html#method.into_raw
582583
///

src/liballoc/sync.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,11 @@ impl<T: ?Sized> Arc<T> {
553553
/// Constructs an `Arc` from a raw pointer.
554554
///
555555
/// The raw pointer must have been previously returned by a call to a
556-
/// [`Arc::into_raw`][into_raw].
556+
/// [`Arc::into_raw`][into_raw], using the same `T`.
557557
///
558-
/// This function is unsafe because improper use may lead to memory problems. For example, a
559-
/// double-free may occur if the function is called twice on the same raw pointer.
558+
/// 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.
560561
///
561562
/// [into_raw]: struct.Arc.html#method.into_raw
562563
///

0 commit comments

Comments
 (0)