Skip to content

Commit 6d48177

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 0454a35 commit 6d48177

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")]
@@ -1139,9 +1142,12 @@ impl<T> AtomicPtr<T> {
11391142
///
11401143
/// # Safety
11411144
///
1142-
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this can be bigger than `align_of::<*mut T>()`).
1145+
/// * `ptr` must be aligned to `align_of::<AtomicPtr<T>>()` (note that on some platforms this
1146+
/// can be bigger than `align_of::<*mut T>()`).
11431147
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
1144-
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`.
1148+
/// * The value behind `ptr` must not be accessed through non-atomic operations whenever
1149+
/// the `AtomicPtr` is used in a `Sync` context (e.g. read or modified in a different
1150+
/// thread).
11451151
///
11461152
/// [valid]: crate::ptr#safety
11471153
#[unstable(feature = "atomic_from_ptr", issue = "108652")]
@@ -2109,10 +2115,13 @@ macro_rules! atomic_int {
21092115
///
21102116
/// # Safety
21112117
///
2112-
/// * `ptr` must be aligned to `align_of::<AtomicBool>()` (note that on some platforms this can be bigger than `align_of::<bool>()`).
2113-
#[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), ">()`).")]
2118+
#[doc = concat!(" * `ptr` must be aligned to \
2119+
`align_of::<", stringify!($atomic_type), ">()` (note that on some platforms this \
2120+
can be bigger than `align_of::<", stringify!($int_type), ">()`).")]
21142121
/// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`.
2115-
/// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`.
2122+
/// * The value behind `ptr` must not be accessed through non-atomic operations whenever the
2123+
#[doc = concat!(" `", stringify!($atomic_type), "`")]
2124+
/// is used in a `Sync` context (e.g. read or modified in a different thread).
21162125
///
21172126
/// [valid]: crate::ptr#safety
21182127
#[unstable(feature = "atomic_from_ptr", issue = "108652")]

0 commit comments

Comments
 (0)