Repository navigation
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Description
Feature gate: #![feature(once_cell_get_mut)]
This is a tracking issue for
OnceCell::get_mut_or_init()OnceCell::get_mut_or_try_init()OnceLock::get_mut_or_init()OnceLock::get_mut_or_try_init()
Public API
pub fn get_mut_or_try_init<F, E>(&mut self, f: F) -> Result<&mut T, E>
where
F: FnOnce() -> Result<T, E> { ... }
pub fn get_mut_or_init<F>(&mut self, f: F) -> &mut T
where
F: FnOnce() -> T { ... }Steps / History
- ACP: Add get_mut_or_init and get_mut_or_try_init for OnceCell libs-team#294
- Implementation: impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock #114788
- Final comment period (FCP)
- Stabilization PR
Unresolved Questions
None yet.
Footnotes
Reacted by Xingcan LAN, B0ney, l.liz, Tobias Bergkvist, James C. Wise, Paul Heinrich, Absolutex, Nikolai Golub, Enduriel, Stepan Koltsov and 5 more
Reacted by Xingcan LAN
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Activity
ChayimFriedman2 commentedon Jul 7, 2024
The documentation seems wrong?
Since it takes
&mut self, this is entirely impossible.The implementation can likewise be simplified a lot by not using any synchronization.
Rollup merge of rust-lang#128457 - juntyr:once-lock-docs, r=tgross35
Unrolled build for rust-lang#128457
tisonkun commentedon Jan 30, 2026
@dtolnay Shall we have an FCP for this feature? I encounter this requriement in stable toolchain today again :P
dtolnay commentedon Jan 30, 2026
I doubt that
get_mut_or_try_initcan be stabilized sooner than #109737.That tracking issue has an unresolved question around
core::ops::Try.dtolnay commentedon Jan 30, 2026
This and #109737 can be stabilized together if we are going to keep
Resultin all the signatures (which is my preference).@rfcbot merge libs-api
rust-rfcbot commentedon Jan 30, 2026
@dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.
coastalwhite commentedon Apr 17, 2026
Bumping this as this only needs 1 more vote to enter the FCP. This would allow a few libraries to move off
once_cell.