Skip to content

Commit 8a7ca93

Browse files
committed
Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-se
Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: #74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed.
2 parents f2d9a3d + 9b51229 commit 8a7ca93

File tree

40 files changed

+163
-156
lines changed

40 files changed

+163
-156
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(let_chains)]
66
#![feature(min_specialization)]
77
#![feature(never_type)]
8-
#![feature(once_cell)]
8+
#![feature(lazy_cell)]
99
#![feature(rustc_attrs)]
1010
#![feature(stmt_expr_attributes)]
1111
#![feature(trusted_step)]

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#![feature(iter_intersperse)]
1111
#![feature(let_chains)]
1212
#![feature(never_type)]
13-
#![feature(once_cell)]
1413
#![recursion_limit = "256"]
1514
#![allow(rustc::potential_query_instability)]
1615
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(int_roundings)]
66
#![feature(let_chains)]
77
#![feature(never_type)]
8-
#![feature(once_cell)]
98
#![feature(strict_provenance)]
109
#![feature(try_blocks)]
1110
#![recursion_limit = "256"]

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![feature(never_type)]
2121
#![feature(type_alias_impl_trait)]
2222
#![feature(new_uninit)]
23-
#![feature(once_cell)]
23+
#![feature(lazy_cell)]
2424
#![feature(rustc_attrs)]
2525
#![feature(negative_impls)]
2626
#![feature(test)]

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
88
#![feature(is_terminal)]
9-
#![feature(once_cell)]
9+
#![feature(lazy_cell)]
1010
#![feature(decl_macro)]
1111
#![recursion_limit = "256"]
1212
#![allow(rustc::potential_query_instability)]

compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(let_chains)]
2-
#![feature(once_cell)]
2+
#![feature(lazy_cell)]
33
#![feature(rustc_attrs)]
44
#![feature(type_alias_impl_trait)]
55
#![deny(rustc::untranslatable_diagnostic)]

compiler/rustc_feature/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! even if it is stabilized or removed, *do not remove it*. Instead, move the
1212
//! symbol to the `accepted` or `removed` modules respectively.
1313
14-
#![feature(once_cell)]
14+
#![feature(lazy_cell)]
1515
#![deny(rustc::untranslatable_diagnostic)]
1616
#![deny(rustc::diagnostic_outside_of_impl)]
1717

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ This API is completely unstable and subject to change.
6767
#![feature(let_chains)]
6868
#![feature(min_specialization)]
6969
#![feature(never_type)]
70-
#![feature(once_cell)]
70+
#![feature(lazy_cell)]
7171
#![feature(slice_partition_dedup)]
7272
#![feature(try_blocks)]
7373
#![feature(is_some_and)]

compiler/rustc_interface/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(decl_macro)]
33
#![feature(internal_output_capture)]
44
#![feature(thread_spawn_unchecked)]
5-
#![feature(once_cell)]
5+
#![feature(lazy_cell)]
66
#![feature(try_blocks)]
77
#![recursion_limit = "256"]
88
#![allow(rustc::potential_query_instability)]

compiler/rustc_metadata/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(generators)]
55
#![feature(iter_from_generator)]
66
#![feature(let_chains)]
7-
#![feature(once_cell)]
87
#![feature(proc_macro_internals)]
98
#![feature(macro_metavar_expr)]
109
#![feature(min_specialization)]

0 commit comments

Comments
 (0)