Skip to content

Commit cc07949

Browse files
committed
Explain safety of unsync::OnceCell::get(&self) in more detail
1 parent af9d29c commit cc07949

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ pub mod unsync {
454454
/// Returns `None` if the cell is empty.
455455
#[inline]
456456
pub fn get(&self) -> Option<&T> {
457-
// Safe due to `inner`'s invariant
457+
// Safe due to `inner`'s invariant of being written to at most once.
458+
// Had multiple writes to `inner` been allowed, a reference to the
459+
// value we return now would become dangling by a write of a
460+
// different value later.
458461
unsafe { &*self.inner.get() }.as_ref()
459462
}
460463

0 commit comments

Comments
 (0)