Skip to content

Commit 04d9d86

Browse files
committed
std: clarify Mutex::get_mut more clearly
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent ae8ab87 commit 04d9d86

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/std/src/sync/poison/mutex.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ impl<T: ?Sized> Mutex<T> {
582582
/// Returns a mutable reference to the underlying data.
583583
///
584584
/// Since this call borrows the `Mutex` mutably, no actual locking needs to
585-
/// take place -- the mutable borrow statically guarantees no locks exist.
585+
/// take place -- the mutable borrow statically guarantees no new locks can be acquired
586+
/// while this reference exists. Note that this method does not clear any previous abandoned locks
587+
/// (e.g., via [`forget()`] on a [`MutexGuard`]).
586588
///
587589
/// # Errors
588590
///
@@ -599,6 +601,8 @@ impl<T: ?Sized> Mutex<T> {
599601
/// *mutex.get_mut().unwrap() = 10;
600602
/// assert_eq!(*mutex.lock().unwrap(), 10);
601603
/// ```
604+
///
605+
/// [`forget()`]: mem::forget
602606
#[stable(feature = "mutex_get_mut", since = "1.6.0")]
603607
pub fn get_mut(&mut self) -> LockResult<&mut T> {
604608
let data = self.data.get_mut();

0 commit comments

Comments
 (0)