-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for Mutex::new()
as const fn
#66806
Comments
This would mean that Rust needs to use its own Mutex implementation (such as via parking_lot) as in general the mutexes provided via the OS can not be made const. It may be possible to do so on some OS's but that can't be generalized to all. It probably makes more sense to make sure you can use parking_lot's Mutex::new as a const fn on stable Rust before trying to do this for std. |
@CryZe Makes some sense that we can't ask the OS for a mutex in compile time. |
This should include |
Looking at the code from my phone Rwlock looks already doable, and I don't quite get why it's on the heap. |
Closing as this isn't really viable to do today (we need to box the system primitives) and isn't likely to get forgotten (i.e., is trivial to implement and widely desirable) once we get something like parking_lot merged. |
This is still listed as part of #57563 |
For those looking for the PR that stabilized this, it is #97791. |
Hi,
I think being able to do
static mut GLOBAL_LOCK: Mutex<Type> = Mutex::new(Type::new())
Is a very important feature, right now you have to do weird jumps with
Option
/MaybeUninit
andOnce
to then return a&'static Mutex<T>
.In practice, the missing pieces here are: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/mutex.rs#L24 and #57349
alexcrichton Pointed out here #66823 (comment) that this also requires
Box
. so that's another missing piece in cost fn for these to be usable in const fn'sI opened this Issue as part of: #57563
The text was updated successfully, but these errors were encountered: