#[Q] Are mutable references (&mut) always not Sync

3 messages · Page 1 of 1 (latest)

dense copper
#

Lets say if we have a mutable reference to a mutable object (either a Sync or a non Sync type) can we say that its &mut would always be a not Sync ?

naive flame
#

A somewhat surprising consequence of the definition is that &mut T is Sync (if T is Sync) even though it seems like that might provide unsynchronized mutation. The trick is that a mutable reference behind a shared reference (that is, & &mut T) becomes read-only, as if it were a & &T. Hence there is no risk of a data race.
https://doc.rust-lang.org/core/marker/trait.Sync.html

#

also note there is nothing you can do with a guarantee that something doesn't implement a trait