From 511fe47e8eaaa429035bb932d4aa7b09789cb2ac Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Tue, 20 Feb 2024 20:55:13 -0700
Subject: [PATCH] Stabilize `LazyCell` and `LazyLock` (`lazy_cell`)
---
core/src/cell.rs | 2 +-
core/src/cell/lazy.rs | 20 +++++++------------
core/tests/lib.rs | 1 -
std/src/lib.rs | 1 -
std/src/sync/lazy_lock.rs | 41 ++++++++++++++++++++++-----------------
std/src/sync/mod.rs | 2 +-
6 files changed, 32 insertions(+), 35 deletions(-)
diff --git a/core/src/cell.rs b/core/src/cell.rs
index 4b491ffdafa70..ac026de95da12 100644
--- a/core/src/cell.rs
+++ b/core/src/cell.rs
@@ -245,7 +245,7 @@ use crate::ptr::{self, NonNull};
mod lazy;
mod once;
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub use lazy::LazyCell;
#[stable(feature = "once_cell", since = "1.70.0")]
pub use once::OnceCell;
diff --git a/core/src/cell/lazy.rs b/core/src/cell/lazy.rs
index 1b213f6a2941b..47eab6fd0163c 100644
--- a/core/src/cell/lazy.rs
+++ b/core/src/cell/lazy.rs
@@ -18,8 +18,6 @@ enum State {
/// # Examples
///
/// ```
-/// #![feature(lazy_cell)]
-///
/// use std::cell::LazyCell;
///
/// let lazy: LazyCell = LazyCell::new(|| {
@@ -36,7 +34,7 @@ enum State {
/// // 92
/// // 92
/// ```
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub struct LazyCell T> {
state: UnsafeCell>,
}
@@ -47,8 +45,6 @@ impl T> LazyCell {
/// # Examples
///
/// ```
- /// #![feature(lazy_cell)]
- ///
/// use std::cell::LazyCell;
///
/// let hello = "Hello, World!".to_string();
@@ -58,7 +54,8 @@ impl T> LazyCell {
/// assert_eq!(&*lazy, "HELLO, WORLD!");
/// ```
#[inline]
- #[unstable(feature = "lazy_cell", issue = "109736")]
+ #[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
+ #[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub const fn new(f: F) -> LazyCell {
LazyCell { state: UnsafeCell::new(State::Uninit(f)) }
}
@@ -70,7 +67,6 @@ impl T> LazyCell {
/// # Examples
///
/// ```
- /// #![feature(lazy_cell)]
/// #![feature(lazy_cell_consume)]
///
/// use std::cell::LazyCell;
@@ -99,8 +95,6 @@ impl T> LazyCell {
/// # Examples
///
/// ```
- /// #![feature(lazy_cell)]
- ///
/// use std::cell::LazyCell;
///
/// let lazy = LazyCell::new(|| 92);
@@ -109,7 +103,7 @@ impl T> LazyCell {
/// assert_eq!(&*lazy, &92);
/// ```
#[inline]
- #[unstable(feature = "lazy_cell", issue = "109736")]
+ #[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub fn force(this: &LazyCell) -> &T {
// SAFETY:
// This invalidates any mutable references to the data. The resulting
@@ -173,7 +167,7 @@ impl LazyCell {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl T> Deref for LazyCell {
type Target = T;
#[inline]
@@ -182,7 +176,7 @@ impl T> Deref for LazyCell {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl Default for LazyCell {
/// Creates a new lazy value using `Default` as the initializing function.
#[inline]
@@ -191,7 +185,7 @@ impl Default for LazyCell {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for LazyCell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_tuple("LazyCell");
diff --git a/core/tests/lib.rs b/core/tests/lib.rs
index 797108a8425de..e6828f6cb4ea6 100644
--- a/core/tests/lib.rs
+++ b/core/tests/lib.rs
@@ -96,7 +96,6 @@
#![feature(pointer_is_aligned_to)]
#![feature(portable_simd)]
#![feature(ptr_metadata)]
-#![feature(lazy_cell)]
#![feature(unsized_tuple_coercion)]
#![feature(const_option)]
#![feature(const_option_ext)]
diff --git a/std/src/lib.rs b/std/src/lib.rs
index 4a18db3d5a3fc..9d6576fa84117 100644
--- a/std/src/lib.rs
+++ b/std/src/lib.rs
@@ -395,7 +395,6 @@
#![feature(edition_panic)]
#![feature(format_args_nl)]
#![feature(get_many_mut)]
-#![feature(lazy_cell)]
#![feature(log_syntax)]
#![feature(test)]
#![feature(trace_macros)]
diff --git a/std/src/sync/lazy_lock.rs b/std/src/sync/lazy_lock.rs
index 27b59cfc8c24d..16d5dc30552fa 100644
--- a/std/src/sync/lazy_lock.rs
+++ b/std/src/sync/lazy_lock.rs
@@ -31,8 +31,6 @@ union Data {
/// Initialize static variables with `LazyLock`.
///
/// ```
-/// #![feature(lazy_cell)]
-///
/// use std::collections::HashMap;
///
/// use std::sync::LazyLock;
@@ -61,8 +59,6 @@ union Data {
/// ```
/// Initialize fields with `LazyLock`.
/// ```
-/// #![feature(lazy_cell)]
-///
/// use std::sync::LazyLock;
///
/// #[derive(Debug)]
@@ -76,8 +72,7 @@ union Data {
/// println!("{}", *data.number);
/// }
/// ```
-
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub struct LazyLock T> {
once: Once,
data: UnsafeCell>,
@@ -85,8 +80,21 @@ pub struct LazyLock T> {
impl T> LazyLock {
/// Creates a new lazy value with the given initializing function.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::sync::LazyLock;
+ ///
+ /// let hello = "Hello, World!".to_string();
+ ///
+ /// let lazy = LazyLock::new(|| hello.to_uppercase());
+ ///
+ /// assert_eq!(&*lazy, "HELLO, WORLD!");
+ /// ```
#[inline]
- #[unstable(feature = "lazy_cell", issue = "109736")]
+ #[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
+ #[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub const fn new(f: F) -> LazyLock {
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
}
@@ -107,7 +115,6 @@ impl T> LazyLock {
/// # Examples
///
/// ```
- /// #![feature(lazy_cell)]
/// #![feature(lazy_cell_consume)]
///
/// use std::sync::LazyLock;
@@ -145,8 +152,6 @@ impl T> LazyLock {
/// # Examples
///
/// ```
- /// #![feature(lazy_cell)]
- ///
/// use std::sync::LazyLock;
///
/// let lazy = LazyLock::new(|| 92);
@@ -155,7 +160,7 @@ impl T> LazyLock {
/// assert_eq!(&*lazy, &92);
/// ```
#[inline]
- #[unstable(feature = "lazy_cell", issue = "109736")]
+ #[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub fn force(this: &LazyLock) -> &T {
this.once.call_once(|| {
// SAFETY: `call_once` only runs this closure once, ever.
@@ -191,7 +196,7 @@ impl LazyLock {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl Drop for LazyLock {
fn drop(&mut self) {
match self.once.state() {
@@ -204,7 +209,7 @@ impl Drop for LazyLock {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl T> Deref for LazyLock {
type Target = T;
@@ -219,7 +224,7 @@ impl T> Deref for LazyLock {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl Default for LazyLock {
/// Creates a new lazy value using `Default` as the initializing function.
#[inline]
@@ -228,7 +233,7 @@ impl Default for LazyLock {
}
}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for LazyLock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_tuple("LazyLock");
@@ -242,13 +247,13 @@ impl fmt::Debug for LazyLock {
// We never create a `&F` from a `&LazyLock` so it is fine
// to not impl `Sync` for `F`.
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
unsafe impl Sync for LazyLock {}
// auto-derived `Send` impl is OK.
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl RefUnwindSafe for LazyLock {}
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
impl UnwindSafe for LazyLock {}
#[cfg(test)]
diff --git a/std/src/sync/mod.rs b/std/src/sync/mod.rs
index e8c35bd48a70b..fb7d601b09478 100644
--- a/std/src/sync/mod.rs
+++ b/std/src/sync/mod.rs
@@ -179,7 +179,7 @@ pub use self::rwlock::{MappedRwLockReadGuard, MappedRwLockWriteGuard};
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
-#[unstable(feature = "lazy_cell", issue = "109736")]
+#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
pub use self::lazy_lock::LazyLock;
#[stable(feature = "once_cell", since = "1.70.0")]
pub use self::once_lock::OnceLock;