Skip to content

Commit 098e8b7

Browse files
authored
Rollup merge of #98218 - kpreid:nostdarc, r=joshtriplett
Document the conditional existence of `alloc::sync` and `alloc::task`. `alloc` declares ```rust #[cfg(target_has_atomic = "ptr")] pub mod sync; ``` but there is no public documentation of this condition. This PR fixes that, so that users of `alloc` can understand how to make their code compile everywhere `alloc` does, if they are writing a library with impls for `Arc`. The wording is copied from `std::sync::atomic::AtomicPtr`, with additional advice on how to `#[cfg]` for it. I feel quite uncertain about whether the paragraph I added to `Arc`'s documentation should actually be there, as it is a distraction for anyone using `std`. On the other hand, maybe more reminders that no_std exists would benefit the ecosystem. Note: `target_has_atomic` is [stabilized](#32976) but [not yet documented in the reference](rust-lang/reference#1171).
2 parents 33d3519 + 5dcc418 commit 098e8b7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

library/alloc/src/sync.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
//! Thread-safe reference-counting pointers.
44
//!
55
//! See the [`Arc<T>`][Arc] documentation for more details.
6+
//!
7+
//! **Note**: This module is only available on platforms that support atomic
8+
//! loads and stores of pointers. This may be detected at compile time using
9+
//! `#[cfg(target_has_atomic = "ptr")]`.
610
711
use core::any::Any;
812
use core::borrow;
@@ -82,6 +86,11 @@ macro_rules! acquire {
8286
/// [`Mutex`][mutex], [`RwLock`][rwlock], or one of the [`Atomic`][atomic]
8387
/// types.
8488
///
89+
/// **Note**: This type is only available on platforms that support atomic
90+
/// loads and stores of pointers, which includes all platforms that support
91+
/// the `std` crate but not all those which only support [`alloc`](crate).
92+
/// This may be detected at compile time using `#[cfg(target_has_atomic = "ptr")]`.
93+
///
8594
/// ## Thread Safety
8695
///
8796
/// Unlike [`Rc<T>`], `Arc<T>` uses atomic operations for its reference

library/alloc/src/task.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![stable(feature = "wake_trait", since = "1.51.0")]
2+
23
//! Types and Traits for working with asynchronous tasks.
4+
//!
5+
//! **Note**: This module is only available on platforms that support atomic
6+
//! loads and stores of pointers. This may be detected at compile time using
7+
//! `#[cfg(target_has_atomic = "ptr")]`.
8+
39
use core::mem::ManuallyDrop;
410
use core::task::{RawWaker, RawWakerVTable, Waker};
511

0 commit comments

Comments
 (0)