Skip to content

Commit

Permalink
Clarify safety comment for A|Rc::as_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed Jun 30, 2020
1 parent d8a9c61 commit fc3dc72
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/liballoc/rc.rs
Expand Up @@ -592,11 +592,9 @@ impl<T: ?Sized> Rc<T> {
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut RcBox<T> = NonNull::as_ptr(this.ptr);

// 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`.
// SAFETY: This cannot go through Deref::deref or Rc::inner.
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
// write through the pointer after the Rc is recovered through `from_raw`.
unsafe { &raw const (*ptr).value }
}

Expand Down
8 changes: 3 additions & 5 deletions src/liballoc/sync.rs
Expand Up @@ -591,11 +591,9 @@ impl<T: ?Sized> Arc<T> {
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);

// 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`.
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner.
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
// write through the pointer after the Rc is recovered through `from_raw`.
unsafe { &raw const (*ptr).data }
}

Expand Down

0 comments on commit fc3dc72

Please sign in to comment.