From 53661a5343d6802227b59d1ad9eee22617e63651 Mon Sep 17 00:00:00 2001 From: Daniel Franklin Date: Tue, 23 Mar 2021 21:19:01 +0000 Subject: [PATCH] Description fixes by danielhenrymantilla Co-authored-by: Daniel Henry-Mantilla --- src/send-and-sync.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/send-and-sync.md b/src/send-and-sync.md index 33860ef..f017b9c 100644 --- a/src/send-and-sync.md +++ b/src/send-and-sync.md @@ -186,14 +186,16 @@ sync either. ```rust # struct Carton(std::ptr::NonNull); -// Safety: Our implementation of DerefMut requires writers to mutably borrow the -// Carton, so the borrow checker will only let us have references to the Carton -// on multiple threads if no one has a mutable reference to the Carton. This -// means we are Sync if T is Sync. +// Safety: Since there exists a public way to go from a `&Carton` to a `&T` +// in an unsynchronized fashion (such as `Deref`), then `Carton` can't be +// `Sync` if `T` isn't. +// Conversely, `Carton` itself does not use any interior mutability whatsoever: +// all the mutations are performed through an exclusive reference (`&mut`). This +// means it suffices that `T` be `Sync` for `Carton` to be `Sync`: unsafe impl Sync for Carton where T: Sync {} ``` -When we assert our type is Send and Sync we need to enforce that every +When we assert our type is Send and Sync we usually need to enforce that every contained type is Send and Sync. When writing custom types that behave like standard library types we can assert that we have the same requirements. For example, the following code asserts that a Carton is Send if the same