Skip to content

Commit

Permalink
std: add safety comment in LazyLock::get
Browse files Browse the repository at this point in the history
  • Loading branch information
joboet committed Jan 27, 2023
1 parent 7165e61 commit 6520488
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/std/src/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 6520488

Please sign in to comment.