about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-08-13 05:30:13 +0000
committerbors <bors@rust-lang.org>2015-08-13 05:30:13 +0000
commit2da80ef114f33250bd9873b53bcdf76ab36fe9cd (patch)
tree508c4ac26df89e5b887f19be681c3fcf07ce5e96 /src/libstd/sys
parentb2aef9d58b3e568834dba85d1b62fca0b5d41cd1 (diff)
parent646eace6ec5db397ba97e86df067792c0cb6be03 (diff)
downloadrust-2da80ef114f33250bd9873b53bcdf76ab36fe9cd.tar.gz
rust-2da80ef114f33250bd9873b53bcdf76ab36fe9cd.zip
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.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/remutex.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs
index 8f416464173..0674618396f 100644
--- a/src/libstd/sys/common/remutex.rs
+++ b/src/libstd/sys/common/remutex.rs
@@ -36,11 +36,18 @@ unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
 /// dropped (falls out of scope), the lock will be unlocked.
 ///
 /// The data protected by the mutex can be accessed through this guard via its
-/// Deref and DerefMut implementations
+/// Deref implementation.
+///
+/// # Mutability
+///
+/// Unlike `MutexGuard`, `ReentrantMutexGuard` does not implement `DerefMut`,
+/// because implementation of the trait would violate Rust’s reference aliasing
+/// rules. Use interior mutability (usually `RefCell`) in order to mutate the
+/// guarded data.
 #[must_use]
 pub struct ReentrantMutexGuard<'a, T: 'a> {
-    // funny underscores due to how Deref/DerefMut currently work (they
-    // disregard field privacy).
+    // funny underscores due to how Deref currently works (it disregards field
+    // privacy).
     __lock: &'a ReentrantMutex<T>,
     __poison: poison::Guard,
 }