Skip to content

Commit

Permalink
Simplify Debug implementation of MutexGuard.
Browse files Browse the repository at this point in the history
Just transparently print the guarded data, instead of wrapping it in
`MutexGuard { lock: Mutex { data: ... } }`.
  • Loading branch information
m-ou-se committed Jan 17, 2019
1 parent 7b55711 commit 2e9deed
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,7 @@ 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 {
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()
fmt::Debug::fmt(&**self, f)
}
}

Expand Down

0 comments on commit 2e9deed

Please sign in to comment.