From becebf3106407b892f25807473e23d6e8f116a1e Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Fri, 10 Jan 2020 19:39:01 +0100 Subject: Ammend Rc/Arc::from_raw() docs regarding unsafety Constructing an Rc/Arc is unsafe even if the wrapped `T` is never dereferenced. --- src/liballoc/rc.rs | 7 ++++--- src/liballoc/sync.rs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 3080a8bf459..60a8e1714b6 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -573,10 +573,11 @@ impl Rc { /// Constructs an `Rc` from a raw pointer. /// /// The raw pointer must have been previously returned by a call to a - /// [`Rc::into_raw`][into_raw]. + /// [`Rc::into_raw`][into_raw] using the same `T`. /// - /// This function is unsafe because improper use may lead to memory problems. For example, a - /// double-free may occur if the function is called twice on the same raw pointer. + /// This function is unsafe because improper use may lead to memory unsafety, + /// even if `T` is never accessed. For example, a double-free may occur if the function is + /// called twice on the same raw pointer. /// /// [into_raw]: struct.Rc.html#method.into_raw /// diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index dc53ad28407..024f9407604 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -553,10 +553,11 @@ impl Arc { /// Constructs an `Arc` from a raw pointer. /// /// The raw pointer must have been previously returned by a call to a - /// [`Arc::into_raw`][into_raw]. + /// [`Arc::into_raw`][into_raw], using the same `T`. /// - /// This function is unsafe because improper use may lead to memory problems. For example, a - /// double-free may occur if the function is called twice on the same raw pointer. + /// This function is unsafe because improper use may lead to memory unsafety, + /// even if `T` is never accessed. For example, a double-free may occur if the function is + /// called twice on the same raw pointer. /// /// [into_raw]: struct.Arc.html#method.into_raw /// -- cgit 1.4.1-3-g733a5