Skip to content

Commit

Permalink
Rollup merge of #67504 - Mark-Simulacrum:note-data-offset, r=Centril
Browse files Browse the repository at this point in the history
Warn against relying on ?Sized being last

Fixes #62522
  • Loading branch information
Centril committed Dec 22, 2019
2 parents c355463 + a34c267 commit ca528fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,8 @@ impl<T: ?Sized> Unpin for Rc<T> { }
unsafe fn data_offset<T: ?Sized>(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.
// Note: This is a detail of the current implementation of the compiler,
// and is not a guaranteed language detail. Do not rely on it outside of std.
data_offset_align(align_of_val(&*ptr))
}

Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,8 @@ impl<T: ?Sized> Unpin for Arc<T> { }
unsafe fn data_offset<T: ?Sized>(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.
// Note: This is a detail of the current implementation of the compiler,
// and is not a guaranteed language detail. Do not rely on it outside of std.
data_offset_align(align_of_val(&*ptr))
}

Expand Down

0 comments on commit ca528fc

Please sign in to comment.