Skip to content

Commit

Permalink
Make MutexGuard's Debug implementation more useful.
Browse files Browse the repository at this point in the history
Fixes #57702.
  • Loading branch information
m-ou-se committed Jan 17, 2019
1 parent daa53a5 commit 7b55711
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,13 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
#[stable(feature = "std_debug", since = "1.16.0")]
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("MutexGuard")
.field("lock", &self.__lock)
.finish()
struct MutexFmt<'a, T: ?Sized>(&'a MutexGuard<'a, T>);
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexFmt<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Mutex").field("data", &&*self.0).finish()
}
}
f.debug_struct("MutexGuard").field("lock", &MutexFmt(self)).finish()
}
}

Expand Down

0 comments on commit 7b55711

Please sign in to comment.