We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0790d34 commit 1419aefCopy full SHA for 1419aef
library/std/src/sync/once_lock.rs
@@ -384,18 +384,10 @@ impl<T> OnceLock<T> {
384
where
385
F: FnOnce() -> Result<T, E>,
386
{
387
- // Fast path check
388
- // NOTE: We need to perform an acquire on the state in this method
389
- // in order to correctly synchronize `LazyLock::force`. This is
390
- // currently done by calling `self.get()`, which in turn calls
391
- // `self.is_initialized()`, which in turn performs the acquire.
392
- if let Some(value) = self.get_mut() {
393
- return Ok(value);
+ if self.get().is_none() {
+ self.initialize(f)?;
394
}
395
- self.initialize(f)?;
396
-
397
debug_assert!(self.is_initialized());
398
399
// SAFETY: The inner value has been initialized
400
Ok(unsafe { self.get_unchecked_mut() })
401
0 commit comments