Skip to content

Commit a9ed9fb

Browse files
authored
Rollup merge of rust-lang#121943 - joshlf:patch-11, r=scottmcm
Clarify atomic bit validity The previous definition used the phrase "representation", which is ambiguous given the current state of memory model nomenclature in Rust. For integer types and for `AtomicPtr<T>`, the new wording clarifies that size and bit validity are guaranteed to match the corresponding native integer type/`*mut T`. For `AtomicBool`, the new wording clarifies that size, alignment, and bit validity are guaranteed to match `bool`. Note that we use the phrase "size and alignment" rather than "layout" since the latter term also implies that the field types are the same. This isn't true - `AtomicXxx` doesn't store an `xxx`, but rather an `UnsafeCell<xxx>`. This distinction is important for some `unsafe` code, which needs to reason about the presence or absence of interior mutability in order to ensure that their code is sound (see e.g. google/zerocopy#251).
2 parents c9f8f34 + a6e3e02 commit a9ed9fb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/core/src/sync/atomic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const EMULATE_ATOMIC_BOOL: bool =
243243

244244
/// A boolean type which can be safely shared between threads.
245245
///
246-
/// This type has the same in-memory representation as a [`bool`].
246+
/// This type has the same size, alignment, and bit validity as a [`bool`].
247247
///
248248
/// **Note**: This type is only available on platforms that support atomic
249249
/// loads and stores of `u8`.
@@ -272,7 +272,7 @@ unsafe impl Sync for AtomicBool {}
272272

273273
/// A raw pointer type which can be safely shared between threads.
274274
///
275-
/// This type has the same in-memory representation as a `*mut T`.
275+
/// This type has the same size and bit validity as a `*mut T`.
276276
///
277277
/// **Note**: This type is only available on platforms that support atomic
278278
/// loads and stores of pointers. Its size depends on the target pointer's size.
@@ -2121,7 +2121,7 @@ macro_rules! atomic_int {
21212121
$int_type:ident $atomic_type:ident) => {
21222122
/// An integer type which can be safely shared between threads.
21232123
///
2124-
/// This type has the same in-memory representation as the underlying
2124+
/// This type has the same size and bit validity as the underlying
21252125
/// integer type, [`
21262126
#[doc = $s_int_type]
21272127
/// `].

0 commit comments

Comments
 (0)