Skip to content

Commit 115447a

Browse files
Rollup merge of rust-lang#52149 - willmo:transparent-atomics, r=cramertj
Add #[repr(transparent)] to Atomic* types This allows them to be used in `#[repr(C)]` structs without warnings. Since rust-lang/rfcs#1649 and rust-lang#35603 they are already documented to have "the same in-memory representation as" their corresponding primitive types. This just makes that explicit. This was briefly part of rust-lang#51395, but was controversial and therefore dropped. But it turns out that it's essentially already documented (which I had forgotten).
2 parents bfac782 + e769dec commit 115447a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/libcore/sync/atomic.rs

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub fn spin_loop_hint() {
124124
/// [`bool`]: ../../../std/primitive.bool.html
125125
#[cfg(target_has_atomic = "8")]
126126
#[stable(feature = "rust1", since = "1.0.0")]
127+
#[repr(transparent)]
127128
pub struct AtomicBool {
128129
v: UnsafeCell<u8>,
129130
}
@@ -147,6 +148,7 @@ unsafe impl Sync for AtomicBool {}
147148
/// This type has the same in-memory representation as a `*mut T`.
148149
#[cfg(target_has_atomic = "ptr")]
149150
#[stable(feature = "rust1", since = "1.0.0")]
151+
#[repr(transparent)]
150152
pub struct AtomicPtr<T> {
151153
p: UnsafeCell<*mut T>,
152154
}
@@ -976,6 +978,7 @@ macro_rules! atomic_int {
976978
///
977979
/// [module-level documentation]: index.html
978980
#[$stable]
981+
#[repr(transparent)]
979982
pub struct $atomic_type {
980983
v: UnsafeCell<$int_type>,
981984
}

0 commit comments

Comments
 (0)