mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #149305 - tisonkun:oncecell-simplify, r=chenyukang
Simplify OnceCell Clone impl Noticed when developing https://github.com/fast/mea/pull/79. This may also apply to `OnceLock`. But unfortunately, we can't construct a completed `Once` beforehand. Note that `OnceCell::from` is marked as [`rustc_const_unstable`](https://github.com/rust-lang/rust/issues/143773) so we don't need an extra `const fn from_value` to leverage possible const convert benefit.
This commit is contained in:
@@ -376,14 +376,10 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
impl<T: Clone> Clone for OnceCell<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> OnceCell<T> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user