]> git.lizzy.rs Git - rust.git/commitdiff
Warn against relying on ?Sized being last
authorMark Rousskov <mark.simulacrum@gmail.com>
Sun, 22 Dec 2019 01:35:41 +0000 (20:35 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Sun, 22 Dec 2019 01:35:41 +0000 (20:35 -0500)
src/liballoc/rc.rs
src/liballoc/sync.rs

index 42a278de98befd7ccfedd347734e616bd31b6ac4..00c4b5462be64d0953644ac5cd981b02bec21bcc 100644 (file)
@@ -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))
 }
 
index a99564c0dac8a97f10beec0df3b74b54de4d181e..37995a7ec794fe414179575ffb7ef5346f26dfb8 100644 (file)
@@ -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))
 }