Skip to content

Commit f8b774f

Browse files
committed
Add explanation for #[must_use] on mutex guards
1 parent 6e49c83 commit f8b774f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/libstd/sync/mutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ unsafe impl<T: ?Sized + Send> Sync for Mutex<T> { }
150150
/// [`lock`]: struct.Mutex.html#method.lock
151151
/// [`try_lock`]: struct.Mutex.html#method.try_lock
152152
/// [`Mutex`]: struct.Mutex.html
153-
#[must_use]
153+
#[must_use = "if unused the Mutex will immediately unlock"]
154154
#[stable(feature = "rust1", since = "1.0.0")]
155155
pub struct MutexGuard<'a, T: ?Sized + 'a> {
156156
// funny underscores due to how Deref/DerefMut currently work (they

src/libstd/sync/rwlock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {}
9494
/// [`read`]: struct.RwLock.html#method.read
9595
/// [`try_read`]: struct.RwLock.html#method.try_read
9696
/// [`RwLock`]: struct.RwLock.html
97-
#[must_use]
97+
#[must_use = "if unused the RwLock will immediately unlock"]
9898
#[stable(feature = "rust1", since = "1.0.0")]
9999
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
100100
__lock: &'a RwLock<T>,
@@ -115,7 +115,7 @@ unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockReadGuard<'a, T> {}
115115
/// [`write`]: struct.RwLock.html#method.write
116116
/// [`try_write`]: struct.RwLock.html#method.try_write
117117
/// [`RwLock`]: struct.RwLock.html
118-
#[must_use]
118+
#[must_use = "if unused the RwLock will immediately unlock"]
119119
#[stable(feature = "rust1", since = "1.0.0")]
120120
pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
121121
__lock: &'a RwLock<T>,

src/libstd/sys_common/remutex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
4141
/// because implementation of the trait would violate Rust’s reference aliasing
4242
/// rules. Use interior mutability (usually `RefCell`) in order to mutate the
4343
/// guarded data.
44-
#[must_use]
44+
#[must_use = "if unused the ReentrantMutex will immediately unlock"]
4545
pub struct ReentrantMutexGuard<'a, T: 'a> {
4646
// funny underscores due to how Deref currently works (it disregards field
4747
// privacy).

0 commit comments

Comments
 (0)