fn test_trait<T:Sync>(_v:T){}
fn test(v:&'static mut i32){
test_trait(v); // ok
}
The definition of trait Sync
in Sync in std::marker - Rust says
The precise definition is: a type
T
is Sync if and only if&T
is Send.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.
According to the definition, that means, Sync
is implemented for & mut i32
if && mut i32
satisfies Send
. By looking at the code in marker.rs
unsafe impl<T: Sync + ?Sized> Send for &T {}
unsafe impl<T: Send + ?Sized> Send for &mut T {}
The condition for implementing Send for &T
is T
satisfies Sync
at least, in this example, that means we implement Send
for & & mut i32
if only & mut i32
satisfies Sync
. This results in a circular requirement.
So, I didn't see how the conclusion
A somewhat surprising consequence of the definition is that &mut T is Sync (if T is Sync)
gets from the first definition
a type
T
is Sync if and only if&T
is Send.
So, where is the place we implement Sync
for & mut T
? Is it a compiler internal implementation that didn't appear in the standard library?