From f00b45890311da955bf2081a0fab2837f3a36a4d Mon Sep 17 00:00:00 2001 From: CAD97 Date: Thu, 7 Jan 2021 12:32:42 -0500 Subject: [PATCH] Tighten/clarify documentation of rc data_offset --- library/alloc/src/rc.rs | 7 ++----- library/alloc/src/sync.rs | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 48b9b8a34f1..61d70a62dca 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2325,11 +2325,8 @@ impl Unpin for Rc {} /// /// # Safety /// -/// This has the same safety requirements as `align_of_val_raw`. In effect: -/// -/// - This function is safe for any argument if `T` is sized, and -/// - if `T` is unsized, the pointer must have appropriate pointer metadata -/// acquired from the real instance that you are getting this offset for. +/// The pointer must point to (and have valid metadata for) a previously +/// valid instance of T, but the T is allowed to be dropped. unsafe fn data_offset(ptr: *const T) -> isize { // Align the unsized value to the end of the `RcBox`. // Because it is ?Sized, it will always be the last field in memory. diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index ae61f4a2384..1ca6b6d6335 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -2476,11 +2476,8 @@ impl Unpin for Arc {} /// /// # Safety /// -/// This has the same safety requirements as `align_of_val_raw`. In effect: -/// -/// - This function is safe for any argument if `T` is sized, and -/// - if `T` is unsized, the pointer must have appropriate pointer metadata -/// acquired from the real instance that you are getting this offset for. +/// The pointer must point to (and have valid metadata for) a previously +/// valid instance of T, but the T is allowed to be dropped. unsafe fn data_offset(ptr: *const T) -> isize { // Align the unsized value to the end of the `ArcInner`. // Because it is `?Sized`, it will always be the last field in memory.