From 6d48177d7e3db84311de3f7be74fbc8be6c4513b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 9 Sep 2023 15:56:42 -0400 Subject: [PATCH] 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 --- library/core/src/sync/atomic.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 22a1c09782ce8..6616c35a533d8 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -346,9 +346,12 @@ impl AtomicBool { /// /// # Safety /// - /// * `ptr` must be aligned to `align_of::()` (note that on some platforms this can be bigger than `align_of::()`). + /// * `ptr` must be aligned to `align_of::()` (note that on some platforms this can + /// be bigger than `align_of::()`). /// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. - /// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. + /// * The value behind `ptr` must not be accessed through non-atomic operations whenever + /// the `AtomicBool` is used in a `Sync` context (e.g. read or modified in a different + /// thread). /// /// [valid]: crate::ptr#safety #[unstable(feature = "atomic_from_ptr", issue = "108652")] @@ -1139,9 +1142,12 @@ impl AtomicPtr { /// /// # Safety /// - /// * `ptr` must be aligned to `align_of::>()` (note that on some platforms this can be bigger than `align_of::<*mut T>()`). + /// * `ptr` must be aligned to `align_of::>()` (note that on some platforms this + /// can be bigger than `align_of::<*mut T>()`). /// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. - /// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. + /// * The value behind `ptr` must not be accessed through non-atomic operations whenever + /// the `AtomicPtr` is used in a `Sync` context (e.g. read or modified in a different + /// thread). /// /// [valid]: crate::ptr#safety #[unstable(feature = "atomic_from_ptr", issue = "108652")] @@ -2109,10 +2115,13 @@ macro_rules! atomic_int { /// /// # Safety /// - /// * `ptr` must be aligned to `align_of::()` (note that on some platforms this can be bigger than `align_of::()`). - #[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), ">()`).")] + #[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), ">()`).")] /// * `ptr` must be [valid] for both reads and writes for the whole lifetime `'a`. - /// * The value behind `ptr` must not be accessed through non-atomic operations for the whole lifetime `'a`. + /// * The value behind `ptr` must not be accessed through non-atomic operations whenever the + #[doc = concat!(" `", stringify!($atomic_type), "`")] + /// is used in a `Sync` context (e.g. read or modified in a different thread). /// /// [valid]: crate::ptr#safety #[unstable(feature = "atomic_from_ptr", issue = "108652")]