Skip to content

Commit df38e15

Browse files
committed
Add const default for OnceCell and OnceLock
Signed-off-by: tison <[email protected]>
1 parent d5525a7 commit df38e15

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

library/core/src/cell/once.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ impl<T> OnceCell<T> {
353353
}
354354

355355
#[stable(feature = "once_cell", since = "1.70.0")]
356-
impl<T> Default for OnceCell<T> {
356+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
357+
impl<T> const Default for OnceCell<T> {
357358
#[inline]
358359
fn default() -> Self {
359360
Self::new()

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
#![feature(cfg_sanitizer_cfi)]
275275
#![feature(cfg_target_thread_local)]
276276
#![feature(cfi_encoding)]
277+
#![feature(const_default)]
277278
#![feature(const_trait_impl)]
278279
#![feature(core_float_math)]
279280
#![feature(decl_macro)]

library/std/src/sync/once_lock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T> {}
582582
impl<T: UnwindSafe> UnwindSafe for OnceLock<T> {}
583583

584584
#[stable(feature = "once_cell", since = "1.70.0")]
585-
impl<T> Default for OnceLock<T> {
585+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
586+
impl<T> const Default for OnceLock<T> {
586587
/// Creates a new uninitialized cell.
587588
///
588589
/// # Example

0 commit comments

Comments
 (0)