diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index 98da015423a5a..7e85d6a063a78 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -111,7 +111,14 @@ impl T> LazyLock { impl LazyLock { /// Get the inner value if it has already been initialized. fn get(&self) -> Option<&T> { - if self.once.is_completed() { Some(unsafe { &*(*self.data.get()).value }) } else { None } + if self.once.is_completed() { + // SAFETY: + // The closure has been run successfully, so `value` has been initialized + // and will not be modified again. + Some(unsafe { &*(*self.data.get()).value }) + } else { + None + } } }