Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4913ab8

Browse files
committed
Stabilize LazyCell and LazyLock (lazy_cell)
1 parent 0b2f194 commit 4913ab8

File tree

34 files changed

+60
-82
lines changed

34 files changed

+60
-82
lines changed

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
309309
}
310310

311311
if let ConstContext::Static(_) = ccx.const_kind() {
312-
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
312+
err.note("consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`");
313313
}
314314

315315
err

compiler/rustc_data_structures/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#![feature(extend_one)]
2525
#![feature(hash_raw_entry)]
2626
#![feature(hasher_prefixfree_extras)]
27-
#![feature(lazy_cell)]
2827
#![feature(lint_reasons)]
2928
#![feature(macro_metavar_expr)]
3029
#![feature(map_try_insert)]

compiler/rustc_error_messages/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![doc(rust_logo)]
22
#![feature(rustdoc_internals)]
3-
#![feature(lazy_cell)]
43
#![feature(rustc_attrs)]
54
#![feature(type_alias_impl_trait)]
65
#![allow(internal_features)]

compiler/rustc_feature/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![allow(internal_features)]
1515
#![feature(rustdoc_internals)]
1616
#![doc(rust_logo)]
17-
#![feature(lazy_cell)]
1817

1918
mod accepted;
2019
mod builtin_attrs;

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ This API is completely unstable and subject to change.
6868
#![feature(iter_intersperse)]
6969
#![feature(let_chains)]
7070
#![feature(never_type)]
71-
#![feature(lazy_cell)]
7271
#![feature(slice_partition_dedup)]
7372
#![feature(try_blocks)]
7473

compiler/rustc_interface/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(decl_macro)]
2-
#![feature(lazy_cell)]
32
#![feature(let_chains)]
43
#![feature(thread_spawn_unchecked)]
54
#![feature(try_blocks)]

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,10 +1316,8 @@ declare_lint! {
13161316
/// * If you are trying to perform a one-time initialization of a global:
13171317
/// * If the value can be computed at compile-time, consider using
13181318
/// const-compatible values (see [Constant Evaluation]).
1319-
/// * For more complex single-initialization cases, consider using a
1320-
/// third-party crate, such as [`lazy_static`] or [`once_cell`].
1321-
/// * If you are using the [nightly channel], consider the new
1322-
/// [`lazy`] module in the standard library.
1319+
/// * For more complex single-initialization cases, consider using
1320+
/// [`std::sync::LazyLock`].
13231321
/// * If you truly need a mutable global, consider using a [`static`],
13241322
/// which has a variety of options:
13251323
/// * Simple data types can be directly defined and mutated with an
@@ -1334,9 +1332,7 @@ declare_lint! {
13341332
/// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
13351333
/// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
13361334
/// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1337-
/// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
1338-
/// [`lazy_static`]: https://crates.io/crates/lazy_static
1339-
/// [`once_cell`]: https://crates.io/crates/once_cell
1335+
/// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
13401336
/// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
13411337
/// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
13421338
pub CONST_ITEM_MUTATION,

compiler/rustc_session/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(let_chains)]
2-
#![feature(lazy_cell)]
32
#![feature(option_get_or_insert_default)]
43
#![feature(rustc_attrs)]
54
#![feature(map_many_mut)]

library/core/src/cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ use crate::ptr::{self, NonNull};
245245
mod lazy;
246246
mod once;
247247

248-
#[unstable(feature = "lazy_cell", issue = "109736")]
248+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
249249
pub use lazy::LazyCell;
250250
#[stable(feature = "once_cell", since = "1.70.0")]
251251
pub use once::OnceCell;

library/core/src/cell/lazy.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ enum State<T, F> {
1818
/// # Examples
1919
///
2020
/// ```
21-
/// #![feature(lazy_cell)]
22-
///
2321
/// use std::cell::LazyCell;
2422
///
2523
/// let lazy: LazyCell<i32> = LazyCell::new(|| {
@@ -36,7 +34,7 @@ enum State<T, F> {
3634
/// // 92
3735
/// // 92
3836
/// ```
39-
#[unstable(feature = "lazy_cell", issue = "109736")]
37+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
4038
pub struct LazyCell<T, F = fn() -> T> {
4139
state: UnsafeCell<State<T, F>>,
4240
}
@@ -47,8 +45,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
4745
/// # Examples
4846
///
4947
/// ```
50-
/// #![feature(lazy_cell)]
51-
///
5248
/// use std::cell::LazyCell;
5349
///
5450
/// let hello = "Hello, World!".to_string();
@@ -58,7 +54,8 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
5854
/// assert_eq!(&*lazy, "HELLO, WORLD!");
5955
/// ```
6056
#[inline]
61-
#[unstable(feature = "lazy_cell", issue = "109736")]
57+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
58+
#[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
6259
pub const fn new(f: F) -> LazyCell<T, F> {
6360
LazyCell { state: UnsafeCell::new(State::Uninit(f)) }
6461
}
@@ -70,7 +67,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
7067
/// # Examples
7168
///
7269
/// ```
73-
/// #![feature(lazy_cell)]
7470
/// #![feature(lazy_cell_consume)]
7571
///
7672
/// use std::cell::LazyCell;
@@ -99,8 +95,6 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
9995
/// # Examples
10096
///
10197
/// ```
102-
/// #![feature(lazy_cell)]
103-
///
10498
/// use std::cell::LazyCell;
10599
///
106100
/// let lazy = LazyCell::new(|| 92);
@@ -109,7 +103,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
109103
/// assert_eq!(&*lazy, &92);
110104
/// ```
111105
#[inline]
112-
#[unstable(feature = "lazy_cell", issue = "109736")]
106+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
113107
pub fn force(this: &LazyCell<T, F>) -> &T {
114108
// SAFETY:
115109
// This invalidates any mutable references to the data. The resulting
@@ -173,7 +167,7 @@ impl<T, F> LazyCell<T, F> {
173167
}
174168
}
175169

176-
#[unstable(feature = "lazy_cell", issue = "109736")]
170+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
177171
impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
178172
type Target = T;
179173
#[inline]
@@ -182,7 +176,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
182176
}
183177
}
184178

185-
#[unstable(feature = "lazy_cell", issue = "109736")]
179+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
186180
impl<T: Default> Default for LazyCell<T> {
187181
/// Creates a new lazy value using `Default` as the initializing function.
188182
#[inline]
@@ -191,7 +185,7 @@ impl<T: Default> Default for LazyCell<T> {
191185
}
192186
}
193187

194-
#[unstable(feature = "lazy_cell", issue = "109736")]
188+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
195189
impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
196190
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
197191
let mut d = f.debug_tuple("LazyCell");

0 commit comments

Comments
 (0)