Skip to content

Commit cced652

Browse files
committed
Use the direct From in Clone for OnceLock<T>
Again, the complexity of `set` is not necessary here.
1 parent d806608 commit cced652

1 file changed

Lines changed: 1 addition & 8 deletions

File tree

library/std/src/sync/once_lock.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
626626
impl<T: Clone> Clone for OnceLock<T> {
627627
#[inline]
628628
fn clone(&self) -> OnceLock<T> {
629-
let cell = Self::new();
630-
if let Some(value) = self.get() {
631-
match cell.set(value.clone()) {
632-
Ok(()) => (),
633-
Err(_) => unreachable!(),
634-
}
635-
}
636-
cell
629+
self.get().cloned().map_or_default(Self::from)
637630
}
638631
}
639632

0 commit comments

Comments
 (0)