Skip to content

Commit 7b55711

Browse files
committed
Make MutexGuard's Debug implementation more useful.
Fixes rust-lang#57702.
1 parent daa53a5 commit 7b55711

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/libstd/sync/mutex.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,13 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
450450
#[stable(feature = "std_debug", since = "1.16.0")]
451451
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
452452
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
453-
f.debug_struct("MutexGuard")
454-
.field("lock", &self.__lock)
455-
.finish()
453+
struct MutexFmt<'a, T: ?Sized>(&'a MutexGuard<'a, T>);
454+
impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexFmt<'a, T> {
455+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
456+
f.debug_struct("Mutex").field("data", &&*self.0).finish()
457+
}
458+
}
459+
f.debug_struct("MutexGuard").field("lock", &MutexFmt(self)).finish()
456460
}
457461
}
458462

0 commit comments

Comments
 (0)