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

sync: Add const fn OnceCell::from_value #5903

Merged
merged 1 commit into from Aug 22, 2023

Conversation

NobodyXu
Copy link
Contributor

@NobodyXu NobodyXu commented Aug 1, 2023

Motivation

<OnceCell<T> as From<T>>::from can be used to construct OnceCell from T directly, however it isn't available in const.

Solution

Add

impl OnceCell {
    #[cfg(not(all(loom, test)))]
    pub const fn from_value(value: T) -> Self;
}

@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Aug 1, 2023
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Aug 1, 2023
@NobodyXu NobodyXu requested a review from Darksonn August 1, 2023 13:16
@NobodyXu NobodyXu force-pushed the once-cell-from-value branch 5 times, most recently from 1a495cc to b4605f9 Compare August 9, 2023 00:36
@NobodyXu NobodyXu force-pushed the once-cell-from-value branch 3 times, most recently from b83fa9c to 9338993 Compare August 11, 2023 00:25
@NobodyXu NobodyXu force-pushed the once-cell-from-value branch 2 times, most recently from d65d15c to e3f7ca1 Compare August 12, 2023 01:17
@NobodyXu NobodyXu requested a review from Darksonn August 12, 2023 01:17
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It would have been better with an Option<T>, but if that's impossible, I'll accept this.

@Darksonn Darksonn merged commit 8955ed5 into tokio-rs:master Aug 22, 2023
72 checks passed
@NobodyXu NobodyXu deleted the once-cell-from-value branch August 22, 2023 11:52
kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Oct 10, 2023
Bumps tokio from 1.32.0 to 1.33.0.

Release notes
Sourced from tokio's releases.

Tokio v1.33.0
1.33.0 (October 9, 2023)
Fixed

io: mark Interest::add with #[must_use] (#6037)
runtime: fix cache line size for RISC-V (#5994)
sync: prevent lock poisoning in watch::Receiver::wait_for (#6021)
task: fix spawn_local source location (#5984)

Changed

macros: use ::core imports instead of ::std in tokio::test (#5973)
sync: use Acquire/Release orderings instead of SeqCst in watch (#6018)

Added

fs: add vectored writes to tokio::fs::File (#5958)
io: add Interest::remove method (#5906)
io: add vectored writes to DuplexStream (#5985)
net: add Apple tvOS support (#6045)
sync: add ?Sized bound to {MutexGuard,OwnedMutexGuard}::map (#5997)
sync: add watch::Receiver::mark_unseen (#5962, #6014, #6017)
sync: add watch::Sender::new (#5998)
sync: add const fn OnceCell::from_value (#5903)

Removed

remove unused stats feature (#5952)

Documented

add missing backticks in code examples (#5938, #6056)
fix typos (#5988, #6030)
process: document that Child::wait is cancel safe (#5977)
sync: add examples for Semaphore (#5939, #5956, #5978, #6031, #6032, #6050)
sync: document that broadcast capacity is a lower bound (#6042)
sync: document that const_new is not instrumented (#6002)
sync: improve cancel-safety documentation for mpsc::Sender::send (#5947)
sync: improve docs for watch channel (#5954)
taskdump: render taskdump documentation on docs.rs (#5972)

Unstable

taskdump: fix potential deadlock (#6036)

#5903: tokio-rs/tokio#5903
#5906: tokio-rs/tokio#5906
#5938: tokio-rs/tokio#5938
#5939: tokio-rs/tokio#5939


... (truncated)


Commits

0457690 chore: prepare Tokio v1.33.0 release (#6059)
4557451 io: implement Seek for SyncIoBridge (#6058)
2bd4376 rt: do not trace tasks while locking OwnedTasks (#6036)
f306bd0 sync: fix unclosed code block in example (#6056)
6b010ac docs: fix new doc warnings in 1.73.0 (#6055)
8cd3383 time: reduce iteration count in short_sleeps test (#6052)
d6ed00c sync: Semaphore doc final cleanup (#6050)
5d29136 docs: add semaphore example for running tests sequentially (#6038)
52b29b3 net: add apple tvos support (#6045)
eaba971 sync: document that broadcast capacity is a lower bound (#6042)
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants