Question on Send and Sync implementation of RwLock

I understand why T: Send bound is present in the Send impl, it's because if we acquire a write lock then we could mem::swap and send our T of to another thread.
I also understand why T: Send bound is present in the Sync impl, the same reasoning from above applies here as well, correct?

But I don't understand the + Sync bound in the Sync impl, why T needs to be both Send and Sync for Rwlock to be Sync? Could someone please explain why? thanks!

Because it allows sharing reads.

Consider:

use std::rc::Rc;

fn main() {
    let lock = std::sync::RwLock::new(Rc::new(0));
    std::thread::scope(|s| {
        s.spawn(|| Rc::clone(&lock.read().unwrap()));
        s.spawn(|| Rc::clone(&lock.read().unwrap()));
    });
}

With your proposed impl that would compile, creating a data race.

No, that is the reason why there is a T: Send bound on the Sync impl. Sync allows you to share a &RwLock<T> to another thread, acquire the write lock and then move out the T.

The reason why there's a T: Send bound on the Send implementation of RwLock<T> is simply because the RwLock<T> contains a T, so if you send the RwLock<T> to another thread you're also sending the T within it.

Similarly to the T: Send requirement for Sync, you can share a &RwLock<T> between threads and then acquire a read lock in different threads, which is equivalent sharing T between those threads and that requires T: Sync.

thanks a lot for providing an example!

thanks for correcting me, it's clear now!