Why does `SyncUnsafeCell: Sync` require `T: Sync`?

In the tracking issue

this is listed as an unresolved question:

  • Should it be Sync only if T is Sync, or should it unconditionally be Sync?

I’ve also come across this limitation in this thread before; comparing to static mut, which doesn’t pose any Sync bounds either.


Also related, an API I had opened afterwards, aiming to replace SyncUnsafeCell entirely.

Which also contains some thoughts about how the T: Sync requirement can be useful, by @mara.

In that ACP issue, I also came across the fact that AtomicPtr is another precedent where raw pointers can be made to cross thread-boundaries easily, without any additional Sync requirements on the pointed-to type, which can be another argument the other way.

2 Likes