Skip to content

Commit f3b13b3

Browse files
authored
Unrolled build for rust-lang#121377
Rollup merge of rust-lang#121377 - pitaj:lazy_cell_fn_pointer, r=dtolnay Stabilize `LazyCell` and `LazyLock` Closes rust-lang#109736 This stabilizes the [`LazyLock`](https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html) and [`LazyCell`](https://doc.rust-lang.org/stable/std/cell/struct.LazyCell.html) types: ```rust static HASHMAP: LazyLock<HashMap<i32, String>> = LazyLock::new(|| { println!("initializing"); let mut m = HashMap::new(); m.insert(13, "Spica".to_string()); m.insert(74, "Hoyten".to_string()); m }); let lazy: LazyCell<i32> = LazyCell::new(|| { println!("initializing"); 92 }); ``` r? libs-api
2 parents 1ba35e9 + 4913ab8 commit f3b13b3

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

+1-1
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

-1
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

-1
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

-1
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

-1
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

-1
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

+3-7
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

-1
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

+1-1
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

+7-13
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");

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
#![feature(pointer_is_aligned_to)]
9797
#![feature(portable_simd)]
9898
#![feature(ptr_metadata)]
99-
#![feature(lazy_cell)]
10099
#![feature(unsized_tuple_coercion)]
101100
#![feature(const_option)]
102101
#![feature(const_option_ext)]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@
395395
#![feature(edition_panic)]
396396
#![feature(format_args_nl)]
397397
#![feature(get_many_mut)]
398-
#![feature(lazy_cell)]
399398
#![feature(log_syntax)]
400399
#![feature(test)]
401400
#![feature(trace_macros)]

library/std/src/sync/lazy_lock.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ union Data<T, F> {
3131
/// Initialize static variables with `LazyLock`.
3232
///
3333
/// ```
34-
/// #![feature(lazy_cell)]
35-
///
3634
/// use std::collections::HashMap;
3735
///
3836
/// use std::sync::LazyLock;
@@ -61,8 +59,6 @@ union Data<T, F> {
6159
/// ```
6260
/// Initialize fields with `LazyLock`.
6361
/// ```
64-
/// #![feature(lazy_cell)]
65-
///
6662
/// use std::sync::LazyLock;
6763
///
6864
/// #[derive(Debug)]
@@ -76,17 +72,29 @@ union Data<T, F> {
7672
/// println!("{}", *data.number);
7773
/// }
7874
/// ```
79-
80-
#[unstable(feature = "lazy_cell", issue = "109736")]
75+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
8176
pub struct LazyLock<T, F = fn() -> T> {
8277
once: Once,
8378
data: UnsafeCell<Data<T, F>>,
8479
}
8580

8681
impl<T, F: FnOnce() -> T> LazyLock<T, F> {
8782
/// Creates a new lazy value with the given initializing function.
83+
///
84+
/// # Examples
85+
///
86+
/// ```
87+
/// use std::sync::LazyLock;
88+
///
89+
/// let hello = "Hello, World!".to_string();
90+
///
91+
/// let lazy = LazyLock::new(|| hello.to_uppercase());
92+
///
93+
/// assert_eq!(&*lazy, "HELLO, WORLD!");
94+
/// ```
8895
#[inline]
89-
#[unstable(feature = "lazy_cell", issue = "109736")]
96+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
97+
#[rustc_const_stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
9098
pub const fn new(f: F) -> LazyLock<T, F> {
9199
LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
92100
}
@@ -107,7 +115,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
107115
/// # Examples
108116
///
109117
/// ```
110-
/// #![feature(lazy_cell)]
111118
/// #![feature(lazy_cell_consume)]
112119
///
113120
/// use std::sync::LazyLock;
@@ -145,8 +152,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
145152
/// # Examples
146153
///
147154
/// ```
148-
/// #![feature(lazy_cell)]
149-
///
150155
/// use std::sync::LazyLock;
151156
///
152157
/// let lazy = LazyLock::new(|| 92);
@@ -155,7 +160,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
155160
/// assert_eq!(&*lazy, &92);
156161
/// ```
157162
#[inline]
158-
#[unstable(feature = "lazy_cell", issue = "109736")]
163+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
159164
pub fn force(this: &LazyLock<T, F>) -> &T {
160165
this.once.call_once(|| {
161166
// SAFETY: `call_once` only runs this closure once, ever.
@@ -191,7 +196,7 @@ impl<T, F> LazyLock<T, F> {
191196
}
192197
}
193198

194-
#[unstable(feature = "lazy_cell", issue = "109736")]
199+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
195200
impl<T, F> Drop for LazyLock<T, F> {
196201
fn drop(&mut self) {
197202
match self.once.state() {
@@ -204,7 +209,7 @@ impl<T, F> Drop for LazyLock<T, F> {
204209
}
205210
}
206211

207-
#[unstable(feature = "lazy_cell", issue = "109736")]
212+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
208213
impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
209214
type Target = T;
210215

@@ -219,7 +224,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
219224
}
220225
}
221226

222-
#[unstable(feature = "lazy_cell", issue = "109736")]
227+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
223228
impl<T: Default> Default for LazyLock<T> {
224229
/// Creates a new lazy value using `Default` as the initializing function.
225230
#[inline]
@@ -228,7 +233,7 @@ impl<T: Default> Default for LazyLock<T> {
228233
}
229234
}
230235

231-
#[unstable(feature = "lazy_cell", issue = "109736")]
236+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
232237
impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
233238
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
234239
let mut d = f.debug_tuple("LazyLock");
@@ -242,13 +247,13 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
242247

243248
// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
244249
// to not impl `Sync` for `F`.
245-
#[unstable(feature = "lazy_cell", issue = "109736")]
250+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
246251
unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
247252
// auto-derived `Send` impl is OK.
248253

249-
#[unstable(feature = "lazy_cell", issue = "109736")]
254+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
250255
impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F> {}
251-
#[unstable(feature = "lazy_cell", issue = "109736")]
256+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
252257
impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F> {}
253258

254259
#[cfg(test)]

library/std/src/sync/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub use self::rwlock::{MappedRwLockReadGuard, MappedRwLockWriteGuard};
179179
#[stable(feature = "rust1", since = "1.0.0")]
180180
pub use self::rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard};
181181

182-
#[unstable(feature = "lazy_cell", issue = "109736")]
182+
#[stable(feature = "lazy_cell", since = "CURRENT_RUSTC_VERSION")]
183183
pub use self::lazy_lock::LazyLock;
184184
#[stable(feature = "once_cell", since = "1.70.0")]
185185
pub use self::once_lock::OnceLock;

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![feature(if_let_guard)]
99
#![feature(impl_trait_in_assoc_type)]
1010
#![feature(iter_intersperse)]
11-
#![feature(lazy_cell)]
1211
#![feature(let_chains)]
1312
#![feature(never_type)]
1413
#![feature(round_char_boundary)]

src/tools/clippy/clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(lazy_cell)]
21
#![feature(let_chains)]
32
#![feature(rustc_private)]
43
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

src/tools/clippy/src/driver.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![allow(rustc::untranslatable_diagnostic)]
33
#![feature(rustc_private)]
44
#![feature(let_chains)]
5-
#![feature(lazy_cell)]
65
#![feature(lint_reasons)]
76
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
87
// warn on lints, that are included in `rust-lang/rust`s bootstrap

src/tools/clippy/tests/compile-test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(lazy_cell)]
21
#![feature(is_sorted)]
32
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
43
#![warn(rust_2018_idioms, unused_lifetimes)]

src/tools/clippy/tests/dogfood.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//!
44
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
55
6-
#![feature(lazy_cell)]
76
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
87
#![warn(rust_2018_idioms, unused_lifetimes)]
98

src/tools/clippy/tests/lint_message_convention.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(lazy_cell)]
21
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
32
#![warn(rust_2018_idioms, unused_lifetimes)]
43

src/tools/clippy/tests/workspace.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lazy_cell)]
2-
31
use std::path::PathBuf;
42
use std::process::Command;
53
use test_utils::{CARGO_CLIPPY_PATH, IS_RUSTC_TEST_SUITE};

tests/ui/borrowck/issue-64453.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | static settings_dir: String = format!("");
1414
| ^^^^^^^^^^^
1515
|
1616
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
17-
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
17+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
1818
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error[E0507]: cannot move out of static item `settings_dir`

tests/ui/consts/issue-16538.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
8-
= note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
8+
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
99

1010
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
1111
--> $DIR/issue-16538.rs:11:22

0 commit comments

Comments
 (0)