Skip to content

Commit

Permalink
Make rc::RcBox and sync::ArcInner repr(C)
Browse files Browse the repository at this point in the history
Future-proof these types in case rustc reorders
the inner fields. As per discussion in PR #68099.
  • Loading branch information
lukaslueg committed Feb 7, 2020
1 parent b4c96a9 commit 586c7e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/liballoc/rc.rs
Expand Up @@ -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>,
Expand Down
4 changes: 4 additions & 0 deletions src/liballoc/sync.rs
Expand Up @@ -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,

Expand Down

0 comments on commit 586c7e3

Please sign in to comment.