Skip to content

Commit fc3dc72

Browse files
committed
Clarify safety comment for A|Rc::as_ptr
1 parent d8a9c61 commit fc3dc72

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/liballoc/rc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,9 @@ impl<T: ?Sized> Rc<T> {
592592
pub fn as_ptr(this: &Self) -> *const T {
593593
let ptr: *mut RcBox<T> = NonNull::as_ptr(this.ptr);
594594

595-
// SAFETY: This cannot go through Deref::deref.
596-
// Instead, we manually offset the pointer rather than manifesting a reference.
597-
// This is so that the returned pointer retains the same provenance as our pointer.
598-
// This is required so that e.g. `get_mut` can write through the pointer
599-
// after the Rc is recovered through `from_raw`.
595+
// SAFETY: This cannot go through Deref::deref or Rc::inner.
596+
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
597+
// write through the pointer after the Rc is recovered through `from_raw`.
600598
unsafe { &raw const (*ptr).value }
601599
}
602600

src/liballoc/sync.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,9 @@ impl<T: ?Sized> Arc<T> {
591591
pub fn as_ptr(this: &Self) -> *const T {
592592
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
593593

594-
// SAFETY: This cannot go through Deref::deref.
595-
// Instead, we manually offset the pointer rather than manifesting a reference.
596-
// This is so that the returned pointer retains the same provenance as our pointer.
597-
// This is required so that e.g. `get_mut` can write through the pointer
598-
// after the Arc is recovered through `from_raw`.
594+
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner.
595+
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
596+
// write through the pointer after the Rc is recovered through `from_raw`.
599597
unsafe { &raw const (*ptr).data }
600598
}
601599

0 commit comments

Comments
 (0)