Skip to content

Commit 767083a

Browse files
committed
Clarify &mut-methods' docs on sync::OnceLock
1 parent 1a95cc6 commit 767083a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

library/std/src/sync/once_lock.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ impl<T> OnceLock<T> {
159159

160160
/// Gets the mutable reference to the underlying value.
161161
///
162-
/// Returns `None` if the cell is uninitialized, or being initialized.
163-
/// This method never blocks.
162+
/// Returns `None` if the cell is uninitialized.
163+
/// This method never blocks. Since it borrows the `OnceLock` mutably,
164+
/// it is statically guaranteed that no active borrows to the `OnceLock`
165+
/// or the underlying data exist, including from other threads.
164166
#[inline]
165167
#[stable(feature = "once_cell", since = "1.70.0")]
166168
pub fn get_mut(&mut self) -> Option<&mut T> {
@@ -315,7 +317,9 @@ impl<T> OnceLock<T> {
315317
/// Gets the mutable reference of the contents of the cell, initializing
316318
/// it to `f()` if the cell was uninitialized.
317319
///
318-
/// This method never blocks.
320+
/// This method never blocks. Since it borrows the `OnceLock` mutably,
321+
/// it is statically guaranteed that no active borrows to the `OnceLock`
322+
/// or the underlying data exist, including from other threads.
319323
///
320324
/// # Panics
321325
///
@@ -405,7 +409,9 @@ impl<T> OnceLock<T> {
405409
/// it to `f()` if the cell was uninitialized. If the cell was uninitialized
406410
/// and `f()` failed, an error is returned.
407411
///
408-
/// This method never blocks.
412+
/// This method never blocks. Since it borrows the `OnceLock` mutably,
413+
/// it is statically guaranteed that no active borrows to the `OnceLock`
414+
/// or the underlying data exist, including from other threads.
409415
///
410416
/// # Panics
411417
///
@@ -469,7 +475,9 @@ impl<T> OnceLock<T> {
469475
///
470476
/// Has no effect and returns `None` if the `OnceLock` was uninitialized.
471477
///
472-
/// Safety is guaranteed by requiring a mutable reference.
478+
/// Since this method borrows the `OnceLock` mutably, it is statically guaranteed that
479+
/// no active borrows to the `OnceLock` or the underlying data exist, including from
480+
/// other threads.
473481
///
474482
/// # Examples
475483
///

0 commit comments

Comments
 (0)