Skip to content

Commit 098e8b7

Browse files
authored
Rollup merge of rust-lang#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](rust-lang#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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy