diff --git a/src/lib.rs b/src/lib.rs index 1b3cf0c65..562d668ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ alloc_layout_extra, box_into_raw_non_null, dropck_eyepatch, - optin_builtin_traits, specialization )] #![deny(warnings, intra_doc_link_resolution_failure, missing_docs)] @@ -42,6 +41,8 @@ //! If you do not depend on these APIs, `cactusref` is a drop-in replacement for //! [`std::rc`]. //! +//! Like [`std::rc`], [`Rc`] and [`Weak`] are `!`[`Send`] and `!`[`Sync`]. +//! //! ## Cycle Detection //! //! `Rc` implements [`Adoptable`] to log bookkeeping entries for strong diff --git a/src/rc.rs b/src/rc.rs index 1d43f6c30..360e5b0b1 100644 --- a/src/rc.rs +++ b/src/rc.rs @@ -29,14 +29,25 @@ use crate::Weak; /// that you have to call them as e.g., [`Rc::get_mut(&mut value)`](Rc::get_mut) /// instead of `value.get_mut()`. This avoids conflicts with methods of the /// inner type `T`. +/// +/// Like [`std::rc::Rc`], `Rc` is `!`[`Send`] and `!`[`Sync`]. +/// +/// ```rust,compile_fail +/// # use cactusref::Rc; +/// fn requires_send(s: T) {} +/// requires_send(Rc::new(5)); +/// ``` +/// +/// ```rust,compile_fail +/// # use cactusref::Rc; +/// fn requires_sync(s: T) {} +/// requires_sync(Rc::new(5)); +/// ``` pub struct Rc { pub(crate) ptr: NonNull>, pub(crate) phantom: PhantomData, } -impl !Send for Rc {} -impl !Sync for Rc {} - impl Rc { /// Constructs a new `Rc`. /// diff --git a/src/weak.rs b/src/weak.rs index 38a8ea7d8..28d124a75 100644 --- a/src/weak.rs +++ b/src/weak.rs @@ -24,6 +24,22 @@ use crate::Rc; /// pointers from children back to their parents. /// /// The typical way to obtain a `Weak` pointer is to call [`Rc::downgrade`]. +/// +/// Like [`std::rc::Weak`], `Weak` is `!`[`Send`] and `!`[`Sync`]. +/// +/// ```rust,compile_fail +/// # use cactusref::Rc; +/// fn requires_send(s: T) {} +/// let item = Rc::new(5); +/// requires_send(Rc::downgrade(&item)); +/// ``` +/// +/// ```rust,compile_fail +/// # use cactusref::Rc; +/// fn requires_sync(s: T) {} +/// let item = Rc::new(5); +/// requires_sync(Rc::downgrade(&item)); +/// ``` pub struct Weak { // This is a `NonNull` to allow optimizing the size of this type in enums, // but it is not necessarily a valid pointer. @@ -33,9 +49,6 @@ pub struct Weak { pub(crate) ptr: NonNull>, } -impl !Send for Weak {} -impl !Sync for Weak {} - impl Weak { /// Constructs a new `Weak`, without allocating any memory. ///