about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorCAD97 <cad97@cad97.com>2019-12-17 15:52:13 -0500
committerCAD97 <cad97@cad97.com>2019-12-17 15:52:13 -0500
commiteb77f7ec6e9460c1ca70fbb7bb655f1a0a1bacfc (patch)
treed940b9c2137b733082ce4c1561f8a15e4a9c59ef /src/liballoc
parentc842f02dee81e52f3b63a8b46021a8e18f143a7e (diff)
downloadrust-eb77f7ec6e9460c1ca70fbb7bb655f1a0a1bacfc.tar.gz
rust-eb77f7ec6e9460c1ca70fbb7bb655f1a0a1bacfc.zip
Add internal safety docs to (A)Rc::into_raw
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/rc.rs5
-rw-r--r--src/liballoc/sync.rs5
2 files changed, 10 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 0205c408299..8c70b0a913a 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -575,6 +575,11 @@ impl<T: ?Sized> Rc<T> {
         let fake_ptr = ptr as *mut T;
         mem::forget(this);
 
+        // SAFETY: This cannot go through Deref::deref.
+        // Instead, we manually offset the pointer rather than manifesting a reference.
+        // This is so that the returned pointer retains the same provenance as our pointer.
+        // This is required so that e.g. `get_mut` can write through the pointer
+        // after the Rc is recovered through `from_raw`.
         unsafe {
             let offset = data_offset(&(*ptr).value);
             set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index de56cb300d3..5c1fa17a626 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -555,6 +555,11 @@ impl<T: ?Sized> Arc<T> {
         let fake_ptr = ptr as *mut T;
         mem::forget(this);
 
+        // SAFETY: This cannot go through Deref::deref.
+        // Instead, we manually offset the pointer rather than manifesting a reference.
+        // This is so that the returned pointer retains the same provenance as our pointer.
+        // This is required so that e.g. `get_mut` can write through the pointer
+        // after the Arc is recovered through `from_raw`.
         unsafe {
             let offset = data_offset(&(*ptr).data);
             set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))