diff options
| author | CAD97 <cad97@cad97.com> | 2020-06-30 12:35:28 -0400 |
|---|---|---|
| committer | CAD97 <cad97@cad97.com> | 2020-06-30 15:01:48 -0400 |
| commit | fc3dc723da8daef495a170e02efb38093e05215e (patch) | |
| tree | 9e05aae7d5d9797b719ceffdb8ebf66984a8c50b /src/liballoc | |
| parent | d8a9c61e1a23b73c04d3058a11d1b8b2a46d635e (diff) | |
| download | rust-fc3dc723da8daef495a170e02efb38093e05215e.tar.gz rust-fc3dc723da8daef495a170e02efb38093e05215e.zip | |
Clarify safety comment for A|Rc::as_ptr
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 8 | ||||
| -rw-r--r-- | src/liballoc/sync.rs | 8 |
2 files changed, 6 insertions, 10 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 423122a6900..8f7b8efd811 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -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 } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 289aea3afcc..27c36f4a569 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -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 } } |
