mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
This commit is contained in:
parent
f98598c6cd
commit
dc4ba57566
@ -5,7 +5,7 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(trusted_step)]
|
#![feature(trusted_step)]
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#![feature(int_roundings)]
|
#![feature(int_roundings)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(strict_provenance)]
|
#![feature(strict_provenance)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![feature(new_uninit)]
|
#![feature(new_uninit)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(negative_impls)]
|
#![feature(negative_impls)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
#![feature(is_terminal)]
|
#![feature(is_terminal)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
//! even if it is stabilized or removed, *do not remove it*. Instead, move the
|
//! even if it is stabilized or removed, *do not remove it*. Instead, move the
|
||||||
//! symbol to the `accepted` or `removed` modules respectively.
|
//! symbol to the `accepted` or `removed` modules respectively.
|
||||||
|
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(slice_partition_dedup)]
|
#![feature(slice_partition_dedup)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(is_some_and)]
|
#![feature(is_some_and)]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#![feature(decl_macro)]
|
#![feature(decl_macro)]
|
||||||
#![feature(internal_output_capture)]
|
#![feature(internal_output_capture)]
|
||||||
#![feature(thread_spawn_unchecked)]
|
#![feature(thread_spawn_unchecked)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#![feature(generators)]
|
#![feature(generators)]
|
||||||
#![feature(iter_from_generator)]
|
#![feature(iter_from_generator)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(proc_macro_internals)]
|
#![feature(proc_macro_internals)]
|
||||||
#![feature(macro_metavar_expr)]
|
#![feature(macro_metavar_expr)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(extern_types)]
|
#![feature(extern_types)]
|
||||||
#![feature(new_uninit)]
|
#![feature(new_uninit)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(trusted_len)]
|
#![feature(trusted_len)]
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#![feature(exact_size_is_empty)]
|
#![feature(exact_size_is_empty)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(trusted_step)]
|
#![feature(trusted_step)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#![feature(map_try_insert)]
|
#![feature(map_try_insert)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(option_get_or_insert_default)]
|
#![feature(option_get_or_insert_default)]
|
||||||
#![feature(trusted_step)]
|
#![feature(trusted_step)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(option_get_or_insert_default)]
|
#![feature(option_get_or_insert_default)]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
#![feature(map_many_mut)]
|
#![feature(map_many_mut)]
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#![feature(slice_flatten)]
|
#![feature(slice_flatten)]
|
||||||
#![feature(thin_box)]
|
#![feature(thin_box)]
|
||||||
#![feature(strict_provenance)]
|
#![feature(strict_provenance)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(drain_keep_rest)]
|
#![feature(drain_keep_rest)]
|
||||||
#![deny(fuzzy_provenance_casts)]
|
#![deny(fuzzy_provenance_casts)]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
@ -202,9 +202,9 @@ use crate::ptr::{self, NonNull};
|
|||||||
mod lazy;
|
mod lazy;
|
||||||
mod once;
|
mod once;
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub use lazy::LazyCell;
|
pub use lazy::LazyCell;
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub use once::OnceCell;
|
pub use once::OnceCell;
|
||||||
|
|
||||||
/// A mutable memory location.
|
/// A mutable memory location.
|
||||||
|
@ -11,7 +11,7 @@ use crate::ops::Deref;
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(lazy_cell)]
|
||||||
///
|
///
|
||||||
/// use std::cell::LazyCell;
|
/// use std::cell::LazyCell;
|
||||||
///
|
///
|
||||||
@ -29,7 +29,7 @@ use crate::ops::Deref;
|
|||||||
/// // 92
|
/// // 92
|
||||||
/// // 92
|
/// // 92
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub struct LazyCell<T, F = fn() -> T> {
|
pub struct LazyCell<T, F = fn() -> T> {
|
||||||
cell: OnceCell<T>,
|
cell: OnceCell<T>,
|
||||||
init: Cell<Option<F>>,
|
init: Cell<Option<F>>,
|
||||||
@ -41,7 +41,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(lazy_cell)]
|
||||||
///
|
///
|
||||||
/// use std::cell::LazyCell;
|
/// use std::cell::LazyCell;
|
||||||
///
|
///
|
||||||
@ -52,7 +52,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||||||
/// assert_eq!(&*lazy, "HELLO, WORLD!");
|
/// assert_eq!(&*lazy, "HELLO, WORLD!");
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub const fn new(init: F) -> LazyCell<T, F> {
|
pub const fn new(init: F) -> LazyCell<T, F> {
|
||||||
LazyCell { cell: OnceCell::new(), init: Cell::new(Some(init)) }
|
LazyCell { cell: OnceCell::new(), init: Cell::new(Some(init)) }
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(lazy_cell)]
|
||||||
///
|
///
|
||||||
/// use std::cell::LazyCell;
|
/// use std::cell::LazyCell;
|
||||||
///
|
///
|
||||||
@ -75,7 +75,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||||||
/// assert_eq!(&*lazy, &92);
|
/// assert_eq!(&*lazy, &92);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub fn force(this: &LazyCell<T, F>) -> &T {
|
pub fn force(this: &LazyCell<T, F>) -> &T {
|
||||||
this.cell.get_or_init(|| match this.init.take() {
|
this.cell.get_or_init(|| match this.init.take() {
|
||||||
Some(f) => f(),
|
Some(f) => f(),
|
||||||
@ -84,7 +84,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
|
impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -93,7 +93,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: Default> Default for LazyCell<T> {
|
impl<T: Default> Default for LazyCell<T> {
|
||||||
/// Creates a new lazy value using `Default` as the initializing function.
|
/// Creates a new lazy value using `Default` as the initializing function.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -102,7 +102,7 @@ impl<T: Default> Default for LazyCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
|
impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("Lazy").field("cell", &self.cell).field("init", &"..").finish()
|
f.debug_struct("Lazy").field("cell", &self.cell).field("init", &"..").finish()
|
||||||
|
@ -16,8 +16,6 @@ use crate::mem;
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
/// let cell = OnceCell::new();
|
/// let cell = OnceCell::new();
|
||||||
@ -29,7 +27,7 @@ use crate::mem;
|
|||||||
/// assert_eq!(value, "Hello, World!");
|
/// assert_eq!(value, "Hello, World!");
|
||||||
/// assert!(cell.get().is_some());
|
/// assert!(cell.get().is_some());
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub struct OnceCell<T> {
|
pub struct OnceCell<T> {
|
||||||
// Invariant: written to at most once.
|
// Invariant: written to at most once.
|
||||||
inner: UnsafeCell<Option<T>>,
|
inner: UnsafeCell<Option<T>>,
|
||||||
@ -39,7 +37,8 @@ impl<T> OnceCell<T> {
|
|||||||
/// Creates a new empty cell.
|
/// Creates a new empty cell.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const fn new() -> OnceCell<T> {
|
pub const fn new() -> OnceCell<T> {
|
||||||
OnceCell { inner: UnsafeCell::new(None) }
|
OnceCell { inner: UnsafeCell::new(None) }
|
||||||
}
|
}
|
||||||
@ -48,7 +47,7 @@ impl<T> OnceCell<T> {
|
|||||||
///
|
///
|
||||||
/// Returns `None` if the cell is empty.
|
/// Returns `None` if the cell is empty.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get(&self) -> Option<&T> {
|
pub fn get(&self) -> Option<&T> {
|
||||||
// SAFETY: Safe due to `inner`'s invariant
|
// SAFETY: Safe due to `inner`'s invariant
|
||||||
unsafe { &*self.inner.get() }.as_ref()
|
unsafe { &*self.inner.get() }.as_ref()
|
||||||
@ -58,7 +57,7 @@ impl<T> OnceCell<T> {
|
|||||||
///
|
///
|
||||||
/// Returns `None` if the cell is empty.
|
/// Returns `None` if the cell is empty.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get_mut(&mut self) -> Option<&mut T> {
|
pub fn get_mut(&mut self) -> Option<&mut T> {
|
||||||
self.inner.get_mut().as_mut()
|
self.inner.get_mut().as_mut()
|
||||||
}
|
}
|
||||||
@ -73,8 +72,6 @@ impl<T> OnceCell<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
/// let cell = OnceCell::new();
|
/// let cell = OnceCell::new();
|
||||||
@ -86,7 +83,7 @@ impl<T> OnceCell<T> {
|
|||||||
/// assert!(cell.get().is_some());
|
/// assert!(cell.get().is_some());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn set(&self, value: T) -> Result<(), T> {
|
pub fn set(&self, value: T) -> Result<(), T> {
|
||||||
// SAFETY: Safe because we cannot have overlapping mutable borrows
|
// SAFETY: Safe because we cannot have overlapping mutable borrows
|
||||||
let slot = unsafe { &*self.inner.get() };
|
let slot = unsafe { &*self.inner.get() };
|
||||||
@ -117,8 +114,6 @@ impl<T> OnceCell<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
/// let cell = OnceCell::new();
|
/// let cell = OnceCell::new();
|
||||||
@ -128,7 +123,7 @@ impl<T> OnceCell<T> {
|
|||||||
/// assert_eq!(value, &92);
|
/// assert_eq!(value, &92);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get_or_init<F>(&self, f: F) -> &T
|
pub fn get_or_init<F>(&self, f: F) -> &T
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
@ -153,7 +148,7 @@ impl<T> OnceCell<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(once_cell_try)]
|
||||||
///
|
///
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
@ -166,7 +161,7 @@ impl<T> OnceCell<T> {
|
|||||||
/// assert_eq!(value, Ok(&92));
|
/// assert_eq!(value, Ok(&92));
|
||||||
/// assert_eq!(cell.get(), Some(&92))
|
/// assert_eq!(cell.get(), Some(&92))
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "once_cell_try", issue = "109737")]
|
||||||
pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E>
|
pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E>
|
||||||
where
|
where
|
||||||
F: FnOnce() -> Result<T, E>,
|
F: FnOnce() -> Result<T, E>,
|
||||||
@ -199,8 +194,6 @@ impl<T> OnceCell<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
/// let cell: OnceCell<String> = OnceCell::new();
|
/// let cell: OnceCell<String> = OnceCell::new();
|
||||||
@ -211,7 +204,7 @@ impl<T> OnceCell<T> {
|
|||||||
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
|
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn into_inner(self) -> Option<T> {
|
pub fn into_inner(self) -> Option<T> {
|
||||||
// Because `into_inner` takes `self` by value, the compiler statically verifies
|
// Because `into_inner` takes `self` by value, the compiler statically verifies
|
||||||
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
|
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
|
||||||
@ -227,8 +220,6 @@ impl<T> OnceCell<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::cell::OnceCell;
|
/// use std::cell::OnceCell;
|
||||||
///
|
///
|
||||||
/// let mut cell: OnceCell<String> = OnceCell::new();
|
/// let mut cell: OnceCell<String> = OnceCell::new();
|
||||||
@ -240,13 +231,13 @@ impl<T> OnceCell<T> {
|
|||||||
/// assert_eq!(cell.get(), None);
|
/// assert_eq!(cell.get(), None);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn take(&mut self) -> Option<T> {
|
pub fn take(&mut self) -> Option<T> {
|
||||||
mem::take(self).into_inner()
|
mem::take(self).into_inner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T> Default for OnceCell<T> {
|
impl<T> Default for OnceCell<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -254,7 +245,7 @@ impl<T> Default for OnceCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
|
impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.get() {
|
match self.get() {
|
||||||
@ -264,7 +255,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: Clone> Clone for OnceCell<T> {
|
impl<T: Clone> Clone for OnceCell<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> OnceCell<T> {
|
fn clone(&self) -> OnceCell<T> {
|
||||||
@ -279,7 +270,7 @@ impl<T: Clone> Clone for OnceCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: PartialEq> PartialEq for OnceCell<T> {
|
impl<T: PartialEq> PartialEq for OnceCell<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
@ -287,10 +278,11 @@ impl<T: PartialEq> PartialEq for OnceCell<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: Eq> Eq for OnceCell<T> {}
|
impl<T: Eq> Eq for OnceCell<T> {}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
|
||||||
impl<T> const From<T> for OnceCell<T> {
|
impl<T> const From<T> for OnceCell<T> {
|
||||||
/// Creates a new `OnceCell<T>` which already contains the given `value`.
|
/// Creates a new `OnceCell<T>` which already contains the given `value`.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -300,5 +292,5 @@ impl<T> const From<T> for OnceCell<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just like for `Cell<T>` this isn't needed, but results in nicer error messages.
|
// Just like for `Cell<T>` this isn't needed, but results in nicer error messages.
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T> !Sync for OnceCell<T> {}
|
impl<T> !Sync for OnceCell<T> {}
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
#![feature(pointer_is_aligned)]
|
#![feature(pointer_is_aligned)]
|
||||||
#![feature(portable_simd)]
|
#![feature(portable_simd)]
|
||||||
#![feature(ptr_metadata)]
|
#![feature(ptr_metadata)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(unsized_tuple_coercion)]
|
#![feature(unsized_tuple_coercion)]
|
||||||
#![feature(const_option)]
|
#![feature(const_option)]
|
||||||
#![feature(const_option_ext)]
|
#![feature(const_option_ext)]
|
||||||
|
@ -339,7 +339,7 @@
|
|||||||
#![feature(edition_panic)]
|
#![feature(edition_panic)]
|
||||||
#![feature(format_args_nl)]
|
#![feature(format_args_nl)]
|
||||||
#![feature(log_syntax)]
|
#![feature(log_syntax)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(saturating_int_impl)]
|
#![feature(saturating_int_impl)]
|
||||||
#![feature(stdsimd)]
|
#![feature(stdsimd)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
@ -26,7 +26,7 @@ union Data<T, F> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(lazy_cell)]
|
||||||
///
|
///
|
||||||
/// use std::collections::HashMap;
|
/// use std::collections::HashMap;
|
||||||
///
|
///
|
||||||
@ -54,7 +54,7 @@ union Data<T, F> {
|
|||||||
/// // Some("Hoyten")
|
/// // Some("Hoyten")
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub struct LazyLock<T, F = fn() -> T> {
|
pub struct LazyLock<T, F = fn() -> T> {
|
||||||
once: Once,
|
once: Once,
|
||||||
data: UnsafeCell<Data<T, F>>,
|
data: UnsafeCell<Data<T, F>>,
|
||||||
@ -64,7 +64,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||||||
/// Creates a new lazy value with the given initializing
|
/// Creates a new lazy value with the given initializing
|
||||||
/// function.
|
/// function.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub const fn new(f: F) -> LazyLock<T, F> {
|
pub const fn new(f: F) -> LazyLock<T, F> {
|
||||||
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
|
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(lazy_cell)]
|
||||||
///
|
///
|
||||||
/// use std::sync::LazyLock;
|
/// use std::sync::LazyLock;
|
||||||
///
|
///
|
||||||
@ -86,7 +86,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
|
|||||||
/// assert_eq!(&*lazy, &92);
|
/// assert_eq!(&*lazy, &92);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub fn force(this: &LazyLock<T, F>) -> &T {
|
pub fn force(this: &LazyLock<T, F>) -> &T {
|
||||||
this.once.call_once(|| {
|
this.once.call_once(|| {
|
||||||
// SAFETY: `call_once` only runs this closure once, ever.
|
// SAFETY: `call_once` only runs this closure once, ever.
|
||||||
@ -122,7 +122,7 @@ impl<T, F> LazyLock<T, F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T, F> Drop for LazyLock<T, F> {
|
impl<T, F> Drop for LazyLock<T, F> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
match self.once.state() {
|
match self.once.state() {
|
||||||
@ -135,7 +135,7 @@ impl<T, F> Drop for LazyLock<T, F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
|
impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: Default> Default for LazyLock<T> {
|
impl<T: Default> Default for LazyLock<T> {
|
||||||
/// Creates a new lazy value using `Default` as the initializing function.
|
/// Creates a new lazy value using `Default` as the initializing function.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -154,7 +154,7 @@ impl<T: Default> Default for LazyLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
|
impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.get() {
|
match self.get() {
|
||||||
@ -166,13 +166,13 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
|
|||||||
|
|
||||||
// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
|
// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
|
||||||
// to not impl `Sync` for `F`
|
// to not impl `Sync` for `F`
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
|
unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
|
||||||
// auto-derived `Send` impl is OK.
|
// auto-derived `Send` impl is OK.
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F> {}
|
impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F> {}
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F> {}
|
impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F> {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -172,9 +172,9 @@ pub use self::poison::{LockResult, PoisonError, TryLockError, TryLockResult};
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "lazy_cell", issue = "109736")]
|
||||||
pub use self::lazy_lock::LazyLock;
|
pub use self::lazy_lock::LazyLock;
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub use self::once_lock::OnceLock;
|
pub use self::once_lock::OnceLock;
|
||||||
|
|
||||||
pub(crate) use self::remutex::{ReentrantMutex, ReentrantMutexGuard};
|
pub(crate) use self::remutex::{ReentrantMutex, ReentrantMutexGuard};
|
||||||
|
@ -14,8 +14,6 @@ use crate::sync::Once;
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// static CELL: OnceLock<String> = OnceLock::new();
|
/// static CELL: OnceLock<String> = OnceLock::new();
|
||||||
@ -32,7 +30,7 @@ use crate::sync::Once;
|
|||||||
/// assert!(value.is_some());
|
/// assert!(value.is_some());
|
||||||
/// assert_eq!(value.unwrap().as_str(), "Hello, World!");
|
/// assert_eq!(value.unwrap().as_str(), "Hello, World!");
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub struct OnceLock<T> {
|
pub struct OnceLock<T> {
|
||||||
once: Once,
|
once: Once,
|
||||||
// Whether or not the value is initialized is tracked by `once.is_completed()`.
|
// Whether or not the value is initialized is tracked by `once.is_completed()`.
|
||||||
@ -40,8 +38,6 @@ pub struct OnceLock<T> {
|
|||||||
/// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl.
|
/// `PhantomData` to make sure dropck understands we're dropping T in our Drop impl.
|
||||||
///
|
///
|
||||||
/// ```compile_fail,E0597
|
/// ```compile_fail,E0597
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// struct A<'a>(&'a str);
|
/// struct A<'a>(&'a str);
|
||||||
@ -63,7 +59,8 @@ impl<T> OnceLock<T> {
|
|||||||
/// Creates a new empty cell.
|
/// Creates a new empty cell.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const fn new() -> OnceLock<T> {
|
pub const fn new() -> OnceLock<T> {
|
||||||
OnceLock {
|
OnceLock {
|
||||||
once: Once::new(),
|
once: Once::new(),
|
||||||
@ -77,7 +74,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// Returns `None` if the cell is empty, or being initialized. This
|
/// Returns `None` if the cell is empty, or being initialized. This
|
||||||
/// method never blocks.
|
/// method never blocks.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get(&self) -> Option<&T> {
|
pub fn get(&self) -> Option<&T> {
|
||||||
if self.is_initialized() {
|
if self.is_initialized() {
|
||||||
// Safe b/c checked is_initialized
|
// Safe b/c checked is_initialized
|
||||||
@ -91,7 +88,7 @@ impl<T> OnceLock<T> {
|
|||||||
///
|
///
|
||||||
/// Returns `None` if the cell is empty. This method never blocks.
|
/// Returns `None` if the cell is empty. This method never blocks.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get_mut(&mut self) -> Option<&mut T> {
|
pub fn get_mut(&mut self) -> Option<&mut T> {
|
||||||
if self.is_initialized() {
|
if self.is_initialized() {
|
||||||
// Safe b/c checked is_initialized and we have a unique access
|
// Safe b/c checked is_initialized and we have a unique access
|
||||||
@ -111,8 +108,6 @@ impl<T> OnceLock<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// static CELL: OnceLock<i32> = OnceLock::new();
|
/// static CELL: OnceLock<i32> = OnceLock::new();
|
||||||
@ -129,7 +124,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn set(&self, value: T) -> Result<(), T> {
|
pub fn set(&self, value: T) -> Result<(), T> {
|
||||||
let mut value = Some(value);
|
let mut value = Some(value);
|
||||||
self.get_or_init(|| value.take().unwrap());
|
self.get_or_init(|| value.take().unwrap());
|
||||||
@ -158,8 +153,6 @@ impl<T> OnceLock<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// let cell = OnceLock::new();
|
/// let cell = OnceLock::new();
|
||||||
@ -169,7 +162,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// assert_eq!(value, &92);
|
/// assert_eq!(value, &92);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn get_or_init<F>(&self, f: F) -> &T
|
pub fn get_or_init<F>(&self, f: F) -> &T
|
||||||
where
|
where
|
||||||
F: FnOnce() -> T,
|
F: FnOnce() -> T,
|
||||||
@ -195,7 +188,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
/// #![feature(once_cell_try)]
|
||||||
///
|
///
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
@ -209,7 +202,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// assert_eq!(cell.get(), Some(&92))
|
/// assert_eq!(cell.get(), Some(&92))
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[unstable(feature = "once_cell_try", issue = "109737")]
|
||||||
pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E>
|
pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E>
|
||||||
where
|
where
|
||||||
F: FnOnce() -> Result<T, E>,
|
F: FnOnce() -> Result<T, E>,
|
||||||
@ -236,8 +229,6 @@ impl<T> OnceLock<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// let cell: OnceLock<String> = OnceLock::new();
|
/// let cell: OnceLock<String> = OnceLock::new();
|
||||||
@ -248,7 +239,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
|
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn into_inner(mut self) -> Option<T> {
|
pub fn into_inner(mut self) -> Option<T> {
|
||||||
self.take()
|
self.take()
|
||||||
}
|
}
|
||||||
@ -262,8 +253,6 @@ impl<T> OnceLock<T> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// let mut cell: OnceLock<String> = OnceLock::new();
|
/// let mut cell: OnceLock<String> = OnceLock::new();
|
||||||
@ -275,7 +264,7 @@ impl<T> OnceLock<T> {
|
|||||||
/// assert_eq!(cell.get(), None);
|
/// assert_eq!(cell.get(), None);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub fn take(&mut self) -> Option<T> {
|
pub fn take(&mut self) -> Option<T> {
|
||||||
if self.is_initialized() {
|
if self.is_initialized() {
|
||||||
self.once = Once::new();
|
self.once = Once::new();
|
||||||
@ -344,17 +333,17 @@ impl<T> OnceLock<T> {
|
|||||||
// scoped thread B, which fills the cell, which is
|
// scoped thread B, which fills the cell, which is
|
||||||
// then destroyed by A. That is, destructor observes
|
// then destroyed by A. That is, destructor observes
|
||||||
// a sent value.
|
// a sent value.
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
unsafe impl<T: Sync + Send> Sync for OnceLock<T> {}
|
unsafe impl<T: Sync + Send> Sync for OnceLock<T> {}
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
unsafe impl<T: Send> Send for OnceLock<T> {}
|
unsafe impl<T: Send> Send for OnceLock<T> {}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T> {}
|
impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T> {}
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: UnwindSafe> UnwindSafe for OnceLock<T> {}
|
impl<T: UnwindSafe> UnwindSafe for OnceLock<T> {}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||||
impl<T> const Default for OnceLock<T> {
|
impl<T> const Default for OnceLock<T> {
|
||||||
/// Creates a new empty cell.
|
/// Creates a new empty cell.
|
||||||
@ -362,8 +351,6 @@ impl<T> const Default for OnceLock<T> {
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
@ -376,7 +363,7 @@ impl<T> const Default for OnceLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
|
impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.get() {
|
match self.get() {
|
||||||
@ -386,7 +373,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: Clone> Clone for OnceLock<T> {
|
impl<T: Clone> Clone for OnceLock<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> OnceLock<T> {
|
fn clone(&self) -> OnceLock<T> {
|
||||||
@ -401,15 +388,13 @@ impl<T: Clone> Clone for OnceLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T> From<T> for OnceLock<T> {
|
impl<T> From<T> for OnceLock<T> {
|
||||||
/// Create a new cell with its contents set to `value`.
|
/// Create a new cell with its contents set to `value`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(once_cell)]
|
|
||||||
///
|
|
||||||
/// use std::sync::OnceLock;
|
/// use std::sync::OnceLock;
|
||||||
///
|
///
|
||||||
/// # fn main() -> Result<(), i32> {
|
/// # fn main() -> Result<(), i32> {
|
||||||
@ -430,7 +415,7 @@ impl<T> From<T> for OnceLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: PartialEq> PartialEq for OnceLock<T> {
|
impl<T: PartialEq> PartialEq for OnceLock<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &OnceLock<T>) -> bool {
|
fn eq(&self, other: &OnceLock<T>) -> bool {
|
||||||
@ -438,10 +423,10 @@ impl<T: PartialEq> PartialEq for OnceLock<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
impl<T: Eq> Eq for OnceLock<T> {}
|
impl<T: Eq> Eq for OnceLock<T> {}
|
||||||
|
|
||||||
#[unstable(feature = "once_cell", issue = "74465")]
|
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
|
||||||
unsafe impl<#[may_dangle] T> Drop for OnceLock<T> {
|
unsafe impl<#[may_dangle] T> Drop for OnceLock<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(type_ascription)]
|
#![feature(type_ascription)]
|
||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(lint_reasons)]
|
#![feature(lint_reasons)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(lint_reasons)]
|
#![feature(lint_reasons)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(once_cell)]
|
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(lint_reasons)]
|
#![feature(lint_reasons)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#![feature(test)] // compiletest_rs requires this attribute
|
#![feature(test)] // compiletest_rs requires this attribute
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![feature(is_sorted)]
|
#![feature(is_sorted)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//!
|
//!
|
||||||
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
|
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
|
||||||
|
|
||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#![feature(once_cell)]
|
#![feature(lazy_cell)]
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![feature(once_cell)]
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
sync::OnceLock,
|
sync::OnceLock,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// check-pass
|
// check-pass
|
||||||
|
|
||||||
#![feature(const_trait_impl, once_cell)]
|
#![feature(const_trait_impl, lazy_cell)]
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![feature(once_cell)]
|
|
||||||
|
|
||||||
fn require_sync<T: Sync>() {}
|
fn require_sync<T: Sync>() {}
|
||||||
//~^ NOTE required by this bound in `require_sync`
|
//~^ NOTE required by this bound in `require_sync`
|
||||||
//~| NOTE required by a bound in `require_sync`
|
//~| NOTE required by a bound in `require_sync`
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error[E0277]: `OnceCell<()>` cannot be shared between threads safely
|
error[E0277]: `OnceCell<()>` cannot be shared between threads safely
|
||||||
--> $DIR/suggest-once-cell.rs:8:20
|
--> $DIR/suggest-once-cell.rs:6:20
|
||||||
|
|
|
|
||||||
LL | require_sync::<std::cell::OnceCell<()>>();
|
LL | require_sync::<std::cell::OnceCell<()>>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^ `OnceCell<()>` cannot be shared between threads safely
|
| ^^^^^^^^^^^^^^^^^^^^^^^ `OnceCell<()>` cannot be shared between threads safely
|
||||||
@ -7,7 +7,7 @@ LL | require_sync::<std::cell::OnceCell<()>>();
|
|||||||
= help: the trait `Sync` is not implemented for `OnceCell<()>`
|
= help: the trait `Sync` is not implemented for `OnceCell<()>`
|
||||||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead
|
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead
|
||||||
note: required by a bound in `require_sync`
|
note: required by a bound in `require_sync`
|
||||||
--> $DIR/suggest-once-cell.rs:3:20
|
--> $DIR/suggest-once-cell.rs:1:20
|
||||||
|
|
|
|
||||||
LL | fn require_sync<T: Sync>() {}
|
LL | fn require_sync<T: Sync>() {}
|
||||||
| ^^^^ required by this bound in `require_sync`
|
| ^^^^ required by this bound in `require_sync`
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![feature(once_cell)]
|
|
||||||
|
|
||||||
fn require_sync<T: Sync>() {}
|
fn require_sync<T: Sync>() {}
|
||||||
//~^ NOTE required by this bound in `require_sync`
|
//~^ NOTE required by this bound in `require_sync`
|
||||||
//~| NOTE required by a bound in `require_sync`
|
//~| NOTE required by a bound in `require_sync`
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error[E0277]: `RefCell<()>` cannot be shared between threads safely
|
error[E0277]: `RefCell<()>` cannot be shared between threads safely
|
||||||
--> $DIR/suggest-ref-cell.rs:8:20
|
--> $DIR/suggest-ref-cell.rs:6:20
|
||||||
|
|
|
|
||||||
LL | require_sync::<std::cell::RefCell<()>>();
|
LL | require_sync::<std::cell::RefCell<()>>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ `RefCell<()>` cannot be shared between threads safely
|
| ^^^^^^^^^^^^^^^^^^^^^^ `RefCell<()>` cannot be shared between threads safely
|
||||||
@ -7,7 +7,7 @@ LL | require_sync::<std::cell::RefCell<()>>();
|
|||||||
= help: the trait `Sync` is not implemented for `RefCell<()>`
|
= help: the trait `Sync` is not implemented for `RefCell<()>`
|
||||||
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead
|
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead
|
||||||
note: required by a bound in `require_sync`
|
note: required by a bound in `require_sync`
|
||||||
--> $DIR/suggest-ref-cell.rs:3:20
|
--> $DIR/suggest-ref-cell.rs:1:20
|
||||||
|
|
|
|
||||||
LL | fn require_sync<T: Sync>() {}
|
LL | fn require_sync<T: Sync>() {}
|
||||||
| ^^^^ required by this bound in `require_sync`
|
| ^^^^ required by this bound in `require_sync`
|
||||||
|
Loading…
Reference in New Issue
Block a user