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.
This commit is contained in:
Lukas Lueg 2020-02-03 18:14:31 +01:00
parent b4c96a9199
commit 586c7e3907
2 changed files with 8 additions and 0 deletions

View File

@ -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>,

View File

@ -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,