about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorLukas Lueg <lukas.lueg@gmail.com>2020-02-03 18:14:31 +0100
committerLukas Lueg <lukas.lueg@gmail.com>2020-02-07 22:59:24 +0100
commit586c7e3907738938db7a6730fd70d7125f5925fa (patch)
tree9235301d3d96ad6f704d735659d33fc3c2c683f7 /src/liballoc
parentb4c96a9199f13c5c1c2afa6258d2b9206c151d9f (diff)
downloadrust-586c7e3907738938db7a6730fd70d7125f5925fa.tar.gz
rust-586c7e3907738938db7a6730fd70d7125f5925fa.zip
Make rc::RcBox and sync::ArcInner repr(C)
Future-proof these types in case rustc reorders
the inner fields. As per discussion in PR #68099.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/rc.rs4
-rw-r--r--src/liballoc/sync.rs4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 1d2222adb9d..751efe0e71e 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -259,6 +259,10 @@ use crate::vec::Vec;
 #[cfg(test)]
 mod tests;
 
+// This is repr(C) to future-proof against possible field-reordering, which
+// would interfere with otherwise safe [into|from]_raw() of transmutable
+// inner types.
+#[repr(C)]
 struct RcBox<T: ?Sized> {
     strong: Cell<usize>,
     weak: Cell<usize>,
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index f9c8da58c75..b44d78f31ec 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -270,6 +270,10 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
     }
 }
 
+// This is repr(C) to future-proof against possible field-reordering, which
+// would interfere with otherwise safe [into|from]_raw() of transmutable
+// inner types.
+#[repr(C)]
 struct ArcInner<T: ?Sized> {
     strong: atomic::AtomicUsize,