Skip to content

Commit 2da80ef

Browse files
committed
Auto merge of #27693 - nagisa:remutex-docs, r=alexcrichton
Initial version of PR had an DerefMut implementation, which was later removed because it may cause mutable reference aliasing. Suggest how to implement mutability with reentrant mutex and remove the claim we implement DerefMut.
2 parents b2aef9d + 646eace commit 2da80ef

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/libstd/sys/common/remutex.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
3636
/// dropped (falls out of scope), the lock will be unlocked.
3737
///
3838
/// The data protected by the mutex can be accessed through this guard via its
39-
/// Deref and DerefMut implementations
39+
/// Deref implementation.
40+
///
41+
/// # Mutability
42+
///
43+
/// Unlike `MutexGuard`, `ReentrantMutexGuard` does not implement `DerefMut`,
44+
/// because implementation of the trait would violate Rust’s reference aliasing
45+
/// rules. Use interior mutability (usually `RefCell`) in order to mutate the
46+
/// guarded data.
4047
#[must_use]
4148
pub struct ReentrantMutexGuard<'a, T: 'a> {
42-
// funny underscores due to how Deref/DerefMut currently work (they
43-
// disregard field privacy).
49+
// funny underscores due to how Deref currently works (it disregards field
50+
// privacy).
4451
__lock: &'a ReentrantMutex<T>,
4552
__poison: poison::Guard,
4653
}

0 commit comments

Comments
 (0)