Skip to content

Commit a700e47

Browse files
committed
Simplify OnceCell Clone impl
Signed-off-by: tison <wander4096@gmail.com>
1 parent c871d09 commit a700e47

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

library/core/src/cell/once.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,10 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
376376
impl<T: Clone> Clone for OnceCell<T> {
377377
#[inline]
378378
fn clone(&self) -> OnceCell<T> {
379-
let res = OnceCell::new();
380-
if let Some(value) = self.get() {
381-
match res.set(value.clone()) {
382-
Ok(()) => (),
383-
Err(_) => unreachable!(),
384-
}
379+
match self.get() {
380+
Some(value) => OnceCell::from(value.clone()),
381+
None => OnceCell::new(),
385382
}
386-
res
387383
}
388384
}
389385

0 commit comments

Comments
 (0)