Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the conditional existence of alloc::sync and alloc::task. #98218

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//! Thread-safe reference-counting pointers.
//!
//! See the [`Arc<T>`][Arc] documentation for more details.
//!
//! **Note**: This module is only available on platforms that support atomic
//! loads and stores of pointers. This may be detected at compile time using
//! `#[cfg(target_has_atomic = "ptr")]`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this might be true today, but in the future I could imagine that we'd have some parts of this module available even without atomics of pointer width.

It's already a bit weird that alloc::sync is not a superset of core::sync, it seems; that seems unusual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this might be true today, but in the future I could imagine that we'd have some parts of this module available even without atomics of pointer width.

The documentation could then be revised at the same time the cfg is removed.

It's already a bit weird that alloc::sync is not a superset of core::sync, it seems; that seems unusual.

That sounds like something worth fixing for consistency, but this change is forward-compatible with that — the note on the modules would just be removed, and the note on Arc kept. (alloc::task is in the same situation — and so technically the Wake trait should have a similar note.)


use core::any::Any;
use core::borrow;
Expand Down Expand Up @@ -82,6 +86,11 @@ macro_rules! acquire {
/// [`Mutex`][mutex], [`RwLock`][rwlock], or one of the [`Atomic`][atomic]
/// types.
///
/// **Note**: This type is only available on platforms that support atomic
/// loads and stores of pointers, which includes all platforms that support
/// the `std` crate but not all those which only support [`alloc`](crate).
/// This may be detected at compile time using `#[cfg(target_has_atomic = "ptr")]`.
///
/// ## Thread Safety
///
/// Unlike [`Rc<T>`], `Arc<T>` uses atomic operations for its reference
Expand Down
6 changes: 6 additions & 0 deletions library/alloc/src/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#![stable(feature = "wake_trait", since = "1.51.0")]

//! Types and Traits for working with asynchronous tasks.
//!
//! **Note**: This module is only available on platforms that support atomic
//! loads and stores of pointers. This may be detected at compile time using
//! `#[cfg(target_has_atomic = "ptr")]`.

use core::mem::ManuallyDrop;
use core::task::{RawWaker, RawWakerVTable, Waker};

Expand Down