diff options
| author | joboet <jonasboettiger@icloud.com> | 2023-01-27 10:11:42 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2023-01-27 10:11:42 +0100 |
| commit | 6520488e37f39a11affd776ab1283a0a3fe8087e (patch) | |
| tree | 522998bfb177bf6d5af666c257fd4eb514e41ddc /library/std/src/sync/lazy_lock.rs | |
| parent | 7165e610a21ff78a76775ad2941ef882814f4342 (diff) | |
| download | rust-6520488e37f39a11affd776ab1283a0a3fe8087e.tar.gz rust-6520488e37f39a11affd776ab1283a0a3fe8087e.zip | |
std: add safety comment in `LazyLock::get`
Diffstat (limited to 'library/std/src/sync/lazy_lock.rs')
| -rw-r--r-- | library/std/src/sync/lazy_lock.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index 98da015423a..7e85d6a063a 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -111,7 +111,14 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> { impl<T, F> LazyLock<T, F> { /// 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 + } } } |
