mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
std: add safety comment in LazyLock::get
This commit is contained in:
parent
7165e610a2
commit
6520488e37
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user