Skip to content

Commit 15eebac

Browse files
authored
Rollup merge of #111065 - est31:send_mut_ref, r=m-ou-se
Explicitly document how Send and Sync relate to references Some of these relations were already mentioned in the text, but that Send is implemented for &mut impl Send was not mentioned, neither did the docs list when &T is Sync. Inspired by the discussion in #110961. [Proof](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ed77bfc3c77ba664400ebc2734f500e6) based on `@lukas-code` 's [example](#110961 (comment)).
2 parents 0213461 + 09c50a0 commit 15eebac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/core/src/marker.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::hash::Hasher;
2424
/// operations. Its cousin [`sync::Arc`][arc] does use atomic operations (incurring
2525
/// some overhead) and thus is `Send`.
2626
///
27-
/// See [the Nomicon](../../nomicon/send-and-sync.html) for more details.
27+
/// See [the Nomicon](../../nomicon/send-and-sync.html) and the [`Sync`] trait for more details.
2828
///
2929
/// [`Rc`]: ../../std/rc/struct.Rc.html
3030
/// [arc]: ../../std/sync/struct.Arc.html
@@ -426,6 +426,11 @@ pub macro Copy($item:item) {
426426
/// becomes read-only, as if it were a `& &T`. Hence there is no risk
427427
/// of a data race.
428428
///
429+
/// A shorter overview of how [`Sync`] and [`Send`] relate to referencing:
430+
/// * `&T` is [`Send`] if and only if `T` is [`Sync`]
431+
/// * `&mut T` is [`Send`] if and only if `T` is [`Send`]
432+
/// * `&T` and `&mut T` are [`Sync`] if and only if `T` is [`Sync`]
433+
///
429434
/// Types that are not `Sync` are those that have "interior
430435
/// mutability" in a non-thread-safe form, such as [`Cell`][cell]
431436
/// and [`RefCell`][refcell]. These types allow for mutation of

0 commit comments

Comments
 (0)