From 586c7e3907738938db7a6730fd70d7125f5925fa Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Mon, 3 Feb 2020 18:14:31 +0100 Subject: [PATCH] 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. --- src/liballoc/rc.rs | 4 ++++ src/liballoc/sync.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 1d2222adb9da4..751efe0e71ec1 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 { strong: Cell, weak: Cell, diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index f9c8da58c75c7..b44d78f31ec9d 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -270,6 +270,10 @@ impl fmt::Debug for Weak { } } +// 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 { strong: atomic::AtomicUsize,