Skip to content

Commit

Permalink
Rollup merge of rust-lang#52149 - willmo:transparent-atomics, r=cramertj
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
GuillaumeGomez authored Jul 10, 2018
2 parents bfac782 + e769dec commit 115447a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn spin_loop_hint() {
/// [`bool`]: ../../../std/primitive.bool.html
#[cfg(target_has_atomic = "8")]
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
pub struct AtomicBool {
v: UnsafeCell<u8>,
}
Expand All @@ -147,6 +148,7 @@ unsafe impl Sync for AtomicBool {}
/// This type has the same in-memory representation as a `*mut T`.
#[cfg(target_has_atomic = "ptr")]
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
pub struct AtomicPtr<T> {
p: UnsafeCell<*mut T>,
}
Expand Down Expand Up @@ -976,6 +978,7 @@ macro_rules! atomic_int {
///
/// [module-level documentation]: index.html
#[$stable]
#[repr(transparent)]
pub struct $atomic_type {
v: UnsafeCell<$int_type>,
}
Expand Down

0 comments on commit 115447a

Please sign in to comment.