Skip to content

Commit 5627b9d

Browse files
committed
Mark Rc, Arc, and their Weaks as #[repr(transparent)].
1 parent 9b4ea39 commit 5627b9d

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

library/alloc/src/rc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ struct RcBox<T: ?Sized> {
306306
#[cfg_attr(not(test), rustc_diagnostic_item = "Rc")]
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
#[rustc_insignificant_dtor]
309+
#[repr(transparent)]
309310
pub struct Rc<T: ?Sized> {
310311
ptr: NonNull<RcBox<T>>,
311312
phantom: PhantomData<RcBox<T>>,
@@ -2143,6 +2144,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
21432144
///
21442145
/// [`upgrade`]: Weak::upgrade
21452146
#[stable(feature = "rc_weak", since = "1.4.0")]
2147+
#[repr(transparent)]
21462148
pub struct Weak<T: ?Sized> {
21472149
// This is a `NonNull` to allow optimizing the size of this type in enums,
21482150
// but it is not necessarily a valid pointer.

library/alloc/src/sync.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ macro_rules! acquire {
232232
/// [rc_examples]: crate::rc#examples
233233
#[cfg_attr(not(test), rustc_diagnostic_item = "Arc")]
234234
#[stable(feature = "rust1", since = "1.0.0")]
235+
#[repr(transparent)]
235236
pub struct Arc<T: ?Sized> {
236237
ptr: NonNull<ArcInner<T>>,
237238
phantom: PhantomData<ArcInner<T>>,
@@ -282,6 +283,7 @@ impl<T: ?Sized> Arc<T> {
282283
///
283284
/// [`upgrade`]: Weak::upgrade
284285
#[stable(feature = "arc_weak", since = "1.4.0")]
286+
#[repr(transparent)]
285287
pub struct Weak<T: ?Sized> {
286288
// This is a `NonNull` to allow optimizing the size of this type in enums,
287289
// but it is not necessarily a valid pointer.

0 commit comments

Comments
 (0)