Pre-RFC: Deprecate then remove `static mut`

I’m just noticing: static mut foo: Foo = …; does not require Foo: Sync, while static foo: SyncUnsafeCell<Foo> = SyncUnsafeCell::new(…); does require Foo: Sync.

#![feature(sync_unsafe_cell)]
use core::cell::SyncUnsafeCell;

static mut P1: *const () = std::ptr::null();
// OKAY

static P2: SyncUnsafeCell<*const ()> = SyncUnsafeCell::new(std::ptr::null());
// ERROR - `*const ()` cannot be shared between threads safely

Is this something where SyncUnsafeCell needs to change anyways? After all, SyncUnsafeCell needs additional synchronization anyways, and that additional synchronization might as well be e.g. mutually exclusive in which case you’d want to require only T: Send, for example. Or maybe many use-case of SyncUnsafeCell would want the Sync after all? (I believe SyncUnsafeCell is probably not intended as a mostly-static mut-replacement, anyways, right? Either way, I’m not sure off the top of my head, what the intended use-cases of it are, anyways.)

1 Like