Skip to content

Commit 586c7e3

Browse files
committed
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.
1 parent b4c96a9 commit 586c7e3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/liballoc/rc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ use crate::vec::Vec;
259259
#[cfg(test)]
260260
mod tests;
261261

262+
// This is repr(C) to future-proof against possible field-reordering, which
263+
// would interfere with otherwise safe [into|from]_raw() of transmutable
264+
// inner types.
265+
#[repr(C)]
262266
struct RcBox<T: ?Sized> {
263267
strong: Cell<usize>,
264268
weak: Cell<usize>,

src/liballoc/sync.rs

+4
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
270270
}
271271
}
272272

273+
// This is repr(C) to future-proof against possible field-reordering, which
274+
// would interfere with otherwise safe [into|from]_raw() of transmutable
275+
// inner types.
276+
#[repr(C)]
273277
struct ArcInner<T: ?Sized> {
274278
strong: atomic::AtomicUsize,
275279

0 commit comments

Comments
 (0)