make RefCell unstably const by Daniel-Aaron-Bloom · Pull Request #137843 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation45 Commits1 Checks10 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@Daniel-Aaron-Bloom

Now that we can do interior mutability in const, most of the RefCell API can be const fn. The main exceptions are APIs which use FnOnce (RefCell::replace_with and Ref[Mut]::[filter_]map[_split]) and RefCell::take which calls Default::default.

Tracking issue: #137844

@rustbot

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Mar 1, 2025

@Daniel-Aaron-Bloom Daniel-Aaron-Bloom changed the titleDraft: make Cell more unstably const make RefCell more unstably const

Mar 1, 2025

@Daniel-Aaron-Bloom

@rustbot label -T-libs +T-libs-api
r? libs-api

@rustbot rustbot added T-libs-api

Relevant to the library API team, which will review and decide on the PR/issue.

and removed T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Mar 1, 2025

@Daniel-Aaron-Bloom Daniel-Aaron-Bloom changed the titlemake RefCell more unstably const make RefCell unstably const

Mar 1, 2025

@tgross35

Cc @rust-lang/wg-const-eval

@RalfJung

The main problem is dropping. Please make sure to also add a test actually using a RefCell; that will probably not work since the Ref/RefMut Drop impls are not const.

RalfJung

@RalfJung

@compiler-errors what is the state of Drop in const? Can one impl const Drop and it will "just work"? Are const Destruct bounds ready for use in std (for APIs that are stable but const-unstable)?

@traviscross

Since we probably all want to hear the answer to that question...

cc @rust-lang/lang

@oli-obk

Are const Destruct bounds ready for use in std (for APIs that are stable but const-unstable)?

No. Until we know what const traits syntax to implement, adding more const trait impls is not something we want. The libstd churn is not worth it

@oli-obk

Can one impl const Drop and it will "just work"?

Yes

@RalfJung

@Daniel-Aaron-Bloom okay so please remove the fn const_drop hack and instead try impl const Drop for BorrowRef and BorrowRefMut. If that does not work, then I think it is better to wait until that works; nobody will be able to use RefCell in const otherwise anyway (not even on nightly).

@Daniel-Aaron-Bloom

Should I also remove try to remove my added private function RefMut::as_mut and use const_deref instead?

@RalfJung

Oh that's what those functions are for?

Sure, seems fine to me as long no incomplete nightly features have to be enabled for this.

RalfJung

RalfJung

RalfJung

RalfJung

@bors

@rust-log-analyzer

This comment has been minimized.

@bors

@oli-obk oli-obk removed the S-blocked

Status: Blocked on something else such as an RFC or other implementation work.

label

Jun 2, 2025

@oli-obk

tgross35

oli-obk

@bors

@Daniel-Aaron-Bloom

@oli-obk

@bors

📌 Commit 1f1000f has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jun 26, 2025

bors added a commit that referenced this pull request

Jun 27, 2025

@bors

…rors

Rollup of 18 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit that referenced this pull request

Jun 27, 2025

@rust-timer

Rollup merge of #137843 - Daniel-Aaron-Bloom:const_cell, r=oli-obk

make RefCell unstably const

Now that we can do interior mutability in const, most of the RefCell API can be const fn. The main exceptions are APIs which use FnOnce (RefCell::replace_with and Ref[Mut]::[filter_]map[_split]) and RefCell::take which calls Default::default.

Tracking issue: #137844

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request

Jul 4, 2025

@compiler-errors

…li-obk

make RefCell unstably const

Now that we can do interior mutability in const, most of the RefCell API can be const fn. The main exceptions are APIs which use FnOnce (RefCell::replace_with and Ref[Mut]::[filter_]map[_split]) and RefCell::take which calls Default::default.

Tracking issue: rust-lang#137844

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request

Jul 4, 2025

@bors

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-libs-api

Relevant to the library API team, which will review and decide on the PR/issue.