about summary refs log tree commit diff
path: root/library/core/src/cell
AgeCommit message (Collapse)AuthorLines
2025-09-01Constify conversion traitsltdk-1/+2
2025-08-03add poisoning documentation to `LazyCell`Connor Tsui-2/+59
2025-07-01Update version placeholdersJosh Stone-1/+1
2025-05-10Rollup merge of #129334 - ChayimFriedman2:more-lazy-methods, r=AmanieuMatthias Krüger-1/+9
Implement (part of) ACP 429: add `DerefMut` to `Lazy[Cell/Lock]` `DerefMut` is instantly stable, as a trait impl. That means this needs an FCP. ``@rustbot`` label +needs-fcp https://github.com/rust-lang/libs-team/issues/429
2025-02-03OnceCell & OnceLock docs: Using (un)initialized consistentlyPyrode-25/+28
2024-12-21Less unwrap() in documentationKornel-5/+7
2024-12-18fix(LazyCell): documentation of get[_mut] was wrongJalil David Salamé Messina-2/+2
- `LazyCell::get`: said it was returning a **mutable** reference. - `LazyCell::get_mut`: said it was returning a reference (the mutable was missing).
2024-11-16Add `DerefMut` for `Lazy[Cell/Lock]` that delegates to the unstable ↵Chayim Refael Friedman-1/+9
`force_mut()`
2024-10-25Re-do recursive const stability checksRalf Jung-0/+1
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-16Auto merge of #131767 - cuviper:bump-stage0, r=Mark-Simulacrumbors-1/+1
Bump bootstrap compiler to 1.83.0-beta.1 https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday
2024-10-15replace placeholder versionJosh Stone-1/+1
(cherry picked from commit 567fd9610cbfd220844443487059335d7e1ff021)
2024-10-14Mark LazyCell::into_inner unstably constTrevor Gross-2/+2
Other cell `into_inner` functions are const and there shouldn't be any problem here. Make the unstable `LazyCell::into_inner` const under the same gate as its stability (`lazy_cell_into_inner`). Tracking issue: https://github.com/rust-lang/rust/issues/125623
2024-09-28stabilize const_cell_into_innerRalf Jung-1/+2
2024-09-18Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=AmanieuJubilee-5/+119
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut` Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18library: Call it really_init_mut to avoid name collisionsJubilee Young-2/+2
2024-09-18library: Destabilize Lazy{Cell,Lock}::{force,deref}_mutJubilee Young-14/+3
2024-09-17Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`Chayim Refael Friedman-6/+131
In the implementation of `force_mut`, I chose performance over safety. For `LazyLock` this isn't really a choice; the code has to be unsafe. But for `LazyCell`, we can have a full-safe implementation, but it will be a bit less performant, so I went with the unsafe approach.
2024-08-21Add `const_cell_into_inner` to `OnceCell`Trevor Gross-1/+2
`Cell` and `RefCell` have their `into_inner` methods const unstable. `OnceCell` has the same logic, so add it under the same gate. Tracking issue: https://github.com/rust-lang/rust/issues/78729
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-11Rename `lazy_cell_consume` to `lazy_cell_into_inner`Trevor Gross-2/+2
Name this something that is less confusable with an atomic consume API for `{Lazy,Once}Lock`.
2024-06-11replace version placeholderPietro Albini-7/+7
2024-06-04Rollup merge of #125504 - mqudsi:once_nominal, r=cuviper许杰友 Jieyou Xu (Joe)-2/+2
Change pedantically incorrect OnceCell/OnceLock wording While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby [technically allowing it to be written to again](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=415c023a6ae1ef35f371a2d3bb1aa735) Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole *categorically* prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference. ```@rustbot``` label +A-rustdocs
2024-05-28update tracking issue for lazy_cell_consumeTrevor Spiteri-1/+1
2024-05-24Change pedantically incorrect OnceCell/OnceLock wordingMahmoud Al-Qudsi-2/+2
While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby technically allowing it to be written to again. Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole categorically prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.
2024-03-27impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLocktison-9/+84
See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051 Signed-off-by: tison <wander4096@gmail.com>
2024-02-20Stabilize `LazyCell` and `LazyLock` (`lazy_cell`)Peter Jaszkowiak-13/+7
2023-10-13Add some optimizationsdaxpedda-5/+3
2023-10-13Implement `OnceCell/Lock::try_insert()`daxpedda-5/+35
2023-07-31Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnayMatthias Krüger-3/+5
Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-04-28replace version placeholdersPietro Albini-16/+16
2023-04-24Auto merge of #106152 - SUPERCILEX:lazycell, r=Amanieubors-0/+28
Add LazyCell::into_inner This enables uses cases that need to extract the evaluated value and do something owned with it.
2023-04-19std: make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent ↵joboet-3/+5
with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-04-16rm const traits in libcoreDeadbeef-2/+1
2023-04-14Add Lazy{Cell,Lock}::into_innerAlex Saveau-0/+28
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-03-30fix typo and adjust commentjoboet-2/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-03-30core: use `pointer::write` to cleanup `LazyCell` initializationjoboet-8/+7
2023-03-30core: improve code documentation for `LazyCell`joboet-5/+24
2023-03-30core: optimize `LazyCell` sizejoboet-11/+59
2023-03-29Documentation updates to better share the purpose of OnceCell/OnceLockTrevor Gross-2/+4
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-36/+28
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-01-19Add `OnceCell<T>: !Sync` impl for diagnosticsNilstrieb-0/+4
2022-12-30Auto merge of #105651 - tgross35:once-cell-inline, r=m-ou-sebors-1/+16
Add #[inline] markers to once_cell methods Added inline markers to all simple methods under the `once_cell` feature. Relates to #74465 and #105587 This should not block #105587
2022-12-27Rollup merge of #103718 - matklad:infer-lazy, r=dtolnayMichael Goulet-3/+1
More inference-friendly API for lazy The signature for new was ``` fn new<F>(f: F) -> Lazy<T, F> ``` Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck. This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.
2022-12-13Add #[inline] marker to OnceCell/LazyCell/OnceLock/LazyLockTrevor Gross-1/+16
2022-11-17Properly link `{Once,Lazy}{Cell,Lock}` in docsMaybe Waffle-2/+12
2022-10-29More inference-friendly API for lazyAleksey Kladov-3/+1
The signature for new was ``` fn new<F>(f: F) -> Lazy<T, F> ``` Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck. This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.
2022-06-16Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`Maybe Waffle-0/+387