Skip to content
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

Feature request: Make Mutex::new/RwLock::new const. #73714

Closed
emilio opened this issue Jun 25, 2020 · 5 comments
Closed

Feature request: Make Mutex::new/RwLock::new const. #73714

emilio opened this issue Jun 25, 2020 · 5 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@emilio
Copy link
Contributor

emilio commented Jun 25, 2020

This is useful for the same reason Mutex::new being const is (#66806).

Right now RwLock::new allocates, which is unfortunate.

The parking_lot crate does this: https://amanieu.github.io/parking_lot/parking_lot/struct.RwLock.html#methods

@RalfJung
Copy link
Member

Since #66806 was closed, I am not sure how useful it is to keep this open? At least there should be one issue covering "const synchronization primitive constructors" in general. And that is blocked on using parking_lot.

@emilio
Copy link
Contributor Author

emilio commented Jun 25, 2020

Ah, sorry, I naively thought it was closed as fixed, rather than as "can't fix". I'm happy to close this if the answer is the same (we can't as long as we use the OS primitive), but if using parking lot is on the table I'm happy to morph this into such an issue.

@RalfJung
Copy link
Member

we can't as long as we use the OS primitive

AFAIK that applies to RwLock as well.

but if using parking lot is on the table I'm happy to morph this into such an issue.

I don't think there is an issue. It might be worth creating one. There was a PR (#56410) but it stalled.

@LeSeulArtichaut LeSeulArtichaut added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 25, 2020
@RalfJung RalfJung added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Jul 12, 2020
@RalfJung RalfJung changed the title Feature request: Make RwLock::new const. Feature request: Make Mutex::new/RwLock::new const. Aug 7, 2020
@jamesmunns
Copy link
Member

I think it may be possible to make RwLock const now, at least from a quick look at Unix and Windows, there doesn't seem to need to be any allocations, and I don't see any data that isn't const-able.

@oli-obk oli-obk removed the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label May 25, 2022
@dtolnay
Copy link
Member

dtolnay commented Jul 4, 2022

Closed by #97791; these will be const in 1.63.

@dtolnay dtolnay closed this as completed Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants