Skip to content
Permalink
Browse files

Warn against relying on ?Sized being last

  • Loading branch information
Mark-Simulacrum committed Dec 22, 2019
1 parent 5535c25 commit a34c2677afeee2747d680536f302a8c5665a65f4
Showing with 4 additions and 0 deletions.
  1. +2 −0 src/liballoc/rc.rs
  2. +2 −0 src/liballoc/sync.rs
@@ -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))
}

@@ -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))
}

0 comments on commit a34c267

Please sign in to comment.
You can’t perform that action at this time.