Skip to content

Commit ae6a1a7

Browse files
authored
Rollup merge of #85529 - tlyu:trylock-errors, r=JohnTitor
doc: clarify Mutex::try_lock, etc. errors Clarify error returns from Mutex::try_lock, RwLock::try_read, RwLock::try_write to make it more obvious that both poisoning and the lock being already locked are possible errors.
2 parents 0264f4f + 0e4f8cb commit ae6a1a7

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

library/std/src/sync/mutex.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,14 @@ impl<T: ?Sized> Mutex<T> {
294294
/// # Errors
295295
///
296296
/// If another user of this mutex panicked while holding the mutex, then
297-
/// this call will return an error if the mutex would otherwise be
298-
/// acquired.
297+
/// this call will return the [`Poisoned`] error if the mutex would
298+
/// otherwise be acquired.
299+
///
300+
/// If the mutex could not be acquired because it is already locked, then
301+
/// this call will return the [`WouldBlock`] error.
302+
///
303+
/// [`Poisoned`]: TryLockError::Poisoned
304+
/// [`WouldBlock`]: TryLockError::WouldBlock
299305
///
300306
/// # Examples
301307
///

library/std/src/sync/rwlock.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,17 @@ impl<T: ?Sized> RwLock<T> {
199199
///
200200
/// # Errors
201201
///
202-
/// This function will return an error if the RwLock is poisoned. An RwLock
203-
/// is poisoned whenever a writer panics while holding an exclusive lock. An
204-
/// error will only be returned if the lock would have otherwise been
202+
/// This function will return the [`Poisoned`] error if the RwLock is poisoned.
203+
/// An RwLock is poisoned whenever a writer panics while holding an exclusive
204+
/// lock. `Poisoned` will only be returned if the lock would have otherwise been
205205
/// acquired.
206206
///
207+
/// This function will return the [`WouldBlock`] error if the RwLock could not
208+
/// be acquired because it was already locked exclusively.
209+
///
210+
/// [`Poisoned`]: TryLockError::Poisoned
211+
/// [`WouldBlock`]: TryLockError::WouldBlock
212+
///
207213
/// # Examples
208214
///
209215
/// ```
@@ -281,10 +287,17 @@ impl<T: ?Sized> RwLock<T> {
281287
///
282288
/// # Errors
283289
///
284-
/// This function will return an error if the RwLock is poisoned. An RwLock
285-
/// is poisoned whenever a writer panics while holding an exclusive lock. An
286-
/// error will only be returned if the lock would have otherwise been
287-
/// acquired.
290+
/// This function will return the [`Poisoned`] error if the RwLock is
291+
/// poisoned. An RwLock is poisoned whenever a writer panics while holding
292+
/// an exclusive lock. `Poisoned` will only be returned if the lock would have
293+
/// otherwise been acquired.
294+
///
295+
/// This function will return the [`WouldBlock`] error if the RwLock could not
296+
/// be acquired because it was already locked exclusively.
297+
///
298+
/// [`Poisoned`]: TryLockError::Poisoned
299+
/// [`WouldBlock`]: TryLockError::WouldBlock
300+
///
288301
///
289302
/// # Examples
290303
///

0 commit comments

Comments
 (0)