Skip to content

Commit

Permalink
Rollup merge of rust-lang#83559 - m-ou-se:rwlock-guard-debug-fix, r=j…
Browse files Browse the repository at this point in the history
…ackh726

Fix Debug implementation for RwLock{Read,Write}Guard.

This would attempt to print the Debug representation of the lock that the guard has locked, which will try to lock again, fail, and just print `"<locked>"` unhelpfully.

After this change, this just prints the contents of the mutex, like the other smart pointers (and MutexGuard) do.

MutexGuard had this problem too: rust-lang#57702
  • Loading branch information
JohnTitor committed Mar 27, 2021
2 parents 53cc806 + d730153 commit 5dc29e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/std/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
#[stable(feature = "std_debug", since = "1.16.0")]
impl<T: fmt::Debug> fmt::Debug for RwLockReadGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RwLockReadGuard").field("lock", &self.lock).finish()
(**self).fmt(f)
}
}

Expand All @@ -487,7 +487,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'_, T> {
#[stable(feature = "std_debug", since = "1.16.0")]
impl<T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RwLockWriteGuard").field("lock", &self.lock).finish()
(**self).fmt(f)
}
}

Expand Down

0 comments on commit 5dc29e1

Please sign in to comment.