diff --git a/library/core/src/cell/once.rs b/library/core/src/cell/once.rs index 1e211ae66e79c..6c71e2216a71b 100644 --- a/library/core/src/cell/once.rs +++ b/library/core/src/cell/once.rs @@ -376,14 +376,10 @@ impl fmt::Debug for OnceCell { impl Clone for OnceCell { #[inline] fn clone(&self) -> OnceCell { - let res = OnceCell::new(); - if let Some(value) = self.get() { - match res.set(value.clone()) { - Ok(()) => (), - Err(_) => unreachable!(), - } + match self.get() { + Some(value) => OnceCell::from(value.clone()), + None => OnceCell::new(), } - res } }