Skip to content

Commit e8809e3

Browse files
authored
Rollup merge of #158157 - cuviper:once_lock-clone, r=tgross35
Use the direct `From` in `Clone for OnceLock<T>` This is a followup to #158101 as again, the complexity of `set` is not necessary here, especially because we can now use that direct `From`. r? tgross35
2 parents 66ad954 + cced652 commit e8809e3

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)