Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/core/src/cell/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ impl<T, F: FnOnce() -> T> DerefMut for LazyCell<T, F> {
}

#[stable(feature = "lazy_cell", since = "1.80.0")]
impl<T: Default> Default for LazyCell<T> {
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<T: Default> const Default for LazyCell<T> {
/// Creates a new lazy value using `Default` as the initializing function.
#[inline]
fn default() -> LazyCell<T> {
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ impl<T, F: FnOnce() -> T> DerefMut for LazyLock<T, F> {
}

#[stable(feature = "lazy_cell", since = "1.80.0")]
impl<T: Default> Default for LazyLock<T> {
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<T: Default> const Default for LazyLock<T> {
/// Creates a new lazy value using `Default` as the initializing function.
#[inline]
fn default() -> LazyLock<T> {
Expand Down
9 changes: 9 additions & 0 deletions library/std/tests/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ fn lazy_default() {
assert_eq!(CALLED.load(SeqCst), 1);
}

#[test]
fn const_lazy_default() {
// using Box as it cannot be initialized in const contexts
const X: LazyLock<Box<u8>> = <_>::default();
const Y: LazyCell<Box<u8>> = <_>::default();
assert_eq!(**X, 0);
assert_eq!(**Y, 0);
}

#[test]
#[cfg_attr(any(target_os = "emscripten", target_os = "wasi"), ignore)] // no threads
fn sync_lazy_new() {
Expand Down
2 changes: 2 additions & 0 deletions library/std/tests/sync/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(const_default)]
#![feature(const_trait_impl)]
#![feature(mapped_lock_guards)]
#![feature(mpmc_channel)]
#![feature(oneshot_channel)]
Expand Down
Loading