Skip to content

Commit f00b458

Browse files
committed
Tighten/clarify documentation of rc data_offset
1 parent 6bc772c commit f00b458

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

library/alloc/src/rc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,11 +2325,8 @@ impl<T: ?Sized> Unpin for Rc<T> {}
23252325
///
23262326
/// # Safety
23272327
///
2328-
/// This has the same safety requirements as `align_of_val_raw`. In effect:
2329-
///
2330-
/// - This function is safe for any argument if `T` is sized, and
2331-
/// - if `T` is unsized, the pointer must have appropriate pointer metadata
2332-
/// acquired from the real instance that you are getting this offset for.
2328+
/// The pointer must point to (and have valid metadata for) a previously
2329+
/// valid instance of T, but the T is allowed to be dropped.
23332330
unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize {
23342331
// Align the unsized value to the end of the `RcBox`.
23352332
// Because it is ?Sized, it will always be the last field in memory.

library/alloc/src/sync.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,11 +2476,8 @@ impl<T: ?Sized> Unpin for Arc<T> {}
24762476
///
24772477
/// # Safety
24782478
///
2479-
/// This has the same safety requirements as `align_of_val_raw`. In effect:
2480-
///
2481-
/// - This function is safe for any argument if `T` is sized, and
2482-
/// - if `T` is unsized, the pointer must have appropriate pointer metadata
2483-
/// acquired from the real instance that you are getting this offset for.
2479+
/// The pointer must point to (and have valid metadata for) a previously
2480+
/// valid instance of T, but the T is allowed to be dropped.
24842481
unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize {
24852482
// Align the unsized value to the end of the `ArcInner`.
24862483
// Because it is `?Sized`, it will always be the last field in memory.

0 commit comments

Comments
 (0)