Skip to content

Commit 066265a

Browse files
committed
Correct documentation for atomic_from_ptr
* Remove duplicate alignment note that mentioned `AtomicBool` with other types * Update safety requirements about when non-atomic operations are allowed
1 parent 268d625 commit 066265a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

library/core/src/sync/atomic.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,12 @@ impl AtomicBool {
346346
///
347347
/// # Safety
348348
///
349-
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can be bigger than `align_of::<bool>()`).
349+
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can
350+
/// be bigger than `align_of::<bool>()`).
350351
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
351-
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`.
352+
/// * The value behind `ptr` must not be accessed through non-atomic operations whenever
353+
/// the `AtomicBool` is used in a `Sync` context (e.g. read or modified in a different
354+
/// thread).
352355
///
353356
/// [valid]: crate::ptr#safety
354357
#[unstable(feature = "atomic_from_ptr", issue = "108652")]
@@ -1140,9 +1143,12 @@ impl<T> AtomicPtr<T> {
11401143
///
11411144
/// # Safety
11421145
///
1143-
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this can be bigger than `align_of::<*mut T>()`).
1146+
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this
1147+
/// can be bigger than `align_of::<*mut T>()`).
11441148
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
1145-
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`.
1149+
/// * The value behind `ptr` must not be accessed through non-atomic operations whenever
1150+
/// the `AtomicPtr` is used in a `Sync` context (e.g. read or modified in a different
1151+
/// thread).
11461152
///
11471153
/// [valid]: crate::ptr#safety
11481154
#[unstable(feature = "atomic_from_ptr", issue = "108652")]
@@ -2111,10 +2117,13 @@ macro_rules! atomic_int {
21112117
///
21122118
/// # Safety
21132119
///
2114-
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can be bigger than `align_of::<bool>()`).
2115-
#[doc = concat!(" * `ptr` must be aligned to `align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this can be bigger than `align_of::<", stringify!($int_type), ">()`).")]
2120+
#[doc = concat!(" * `ptr` must be aligned to \
2121+
`align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this \
2122+
can be bigger than `align_of::<", stringify!($int_type), ">()`).")]
21162123
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
2117-
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`.
2124+
/// * The value behind `ptr` must not be accessed through non-atomic operations whenever the
2125+
#[doc = concat!(" `", stringify!($atomic_type), "`")]
2126+
/// is used in a `Sync` context (e.g. read or modified in a different thread).
21182127
///
21192128
/// [valid]: crate::ptr#safety
21202129
#[unstable(feature = "atomic_from_ptr", issue = "108652")]

0 commit comments

Comments
 (0)