Skip to content

Commit

Permalink
Add #[repr(transparent)] to Atomic* types
Browse files Browse the repository at this point in the history
This allows them to be used in #[repr(C)] structs without warnings. Since rust-lang/rfcs#1649 and #35603 they are already documented to have "the same in-memory representation as" their corresponding primitive types. This just makes that explicit.
  • Loading branch information
willmo committed Jul 8, 2018
1 parent 9fd3d78 commit e769dec
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 e769dec

Please sign in to comment.