Skip to content

make RefCell unstably const #137843

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

Merged
merged 1 commit into from
Jun 27, 2025
Merged

Conversation

Daniel-Aaron-Bloom
Copy link
Contributor

@Daniel-Aaron-Bloom Daniel-Aaron-Bloom commented Mar 1, 2025

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
Copy link
Collaborator

rustbot commented Mar 1, 2025

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 title Draft: make Cell more unstably const make RefCell more unstably const Mar 1, 2025
@Daniel-Aaron-Bloom
Copy link
Contributor Author

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

@Daniel-Aaron-Bloom Daniel-Aaron-Bloom marked this pull request as ready for review March 1, 2025 07:29
@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
@rustbot rustbot assigned joshtriplett and unassigned Amanieu Mar 1, 2025
@Daniel-Aaron-Bloom Daniel-Aaron-Bloom changed the title make RefCell more unstably const make RefCell unstably const Mar 1, 2025
@Daniel-Aaron-Bloom Daniel-Aaron-Bloom changed the title make RefCell unstably const make RefCell unstably const Mar 1, 2025
@Daniel-Aaron-Bloom Daniel-Aaron-Bloom changed the title make RefCell unstably const make RefCell unstably const Mar 1, 2025
@tgross35
Copy link
Contributor

tgross35 commented Mar 2, 2025

Cc @rust-lang/wg-const-eval

@RalfJung
Copy link
Member

RalfJung commented Mar 3, 2025

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
Copy link
Member

RalfJung commented Mar 3, 2025

@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
Copy link
Contributor

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

cc @rust-lang/lang

@oli-obk
Copy link
Contributor

oli-obk commented Mar 3, 2025

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
Copy link
Contributor

oli-obk commented Mar 3, 2025

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

Yes

@RalfJung
Copy link
Member

RalfJung commented Mar 3, 2025

@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
Copy link
Contributor Author

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

@RalfJung
Copy link
Member

RalfJung commented Mar 3, 2025

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.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 27, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2025
@bors
Copy link
Collaborator

bors commented May 5, 2025

☔ The latest upstream changes (presumably #140646) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 1, 2025

☔ The latest upstream changes (presumably #141842) made this pull request unmergeable. Please resolve the merge conflicts.

@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
Copy link
Contributor

oli-obk commented Jun 2, 2025

With #119899 this is unblocked

@bors
Copy link
Collaborator

bors commented Jun 17, 2025

☔ The latest upstream changes (presumably #142613) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2025

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 26, 2025

📌 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
…rors

Rollup of 18 pull requests

Successful merges:

 - #137843 (make RefCell unstably const)
 - #140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns)
 - #142549 (small iter.intersperse.fold() optimization)
 - #142637 (Remove some glob imports from the type system)
 - #142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation)
 - #142700 (Remove incorrect comments in `Weak`)
 - #142927 (Add note to `find_const_ty_from_env`)
 - #142967 (Fix RwLock::try_write documentation for WouldBlock condition)
 - #142986 (Port `#[export_name]` to the new attribute parsing infrastructure)
 - #143001 (Rename run always )
 - #143010 (Update `browser-ui-test` version to `0.20.7`)
 - #143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`)
 - #143033 (Expand const-stabilized API links in relnotes)
 - #143041 (Remove cache for citool)
 - #143056 (Move an ACE test out of the GCI directory)
 - #143059 (Fix 1.88 relnotes)
 - #143067 (Tracking issue number for `iter_macro`)
 - #143073 (Fix some fixmes that were waiting for let chains)

Failed merges:

 - #143020 (codegen_fn_attrs: make comment more precise)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0446a0d into rust-lang:master Jun 27, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 27, 2025
rust-timer added a commit that referenced this pull request Jun 27, 2025
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
@Daniel-Aaron-Bloom Daniel-Aaron-Bloom deleted the const_cell branch June 27, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants