Rollup merge of #83561 - m-ou-se:lock-debug, r=jackh726
Improve Debug implementations of Mutex and RwLock. This improves the Debug implementations of Mutex and RwLock. They now show the poison flag and use debug_non_exhaustive. (See #67364.)
This commit is contained in:
commit
a800d7f63f
@ -441,10 +441,13 @@ impl<T: ?Sized + Default> Default for Mutex<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut d = f.debug_struct("Mutex");
|
||||
match self.try_lock() {
|
||||
Ok(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(),
|
||||
Ok(guard) => {
|
||||
d.field("data", &&*guard);
|
||||
}
|
||||
Err(TryLockError::Poisoned(err)) => {
|
||||
f.debug_struct("Mutex").field("data", &&**err.get_ref()).finish()
|
||||
d.field("data", &&**err.get_ref());
|
||||
}
|
||||
Err(TryLockError::WouldBlock) => {
|
||||
struct LockedPlaceholder;
|
||||
@ -453,10 +456,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
f.write_str("<locked>")
|
||||
}
|
||||
}
|
||||
|
||||
f.debug_struct("Mutex").field("data", &LockedPlaceholder).finish()
|
||||
d.field("data", &LockedPlaceholder);
|
||||
}
|
||||
}
|
||||
d.field("poisoned", &self.poison.get());
|
||||
d.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,10 +422,13 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut d = f.debug_struct("RwLock");
|
||||
match self.try_read() {
|
||||
Ok(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(),
|
||||
Ok(guard) => {
|
||||
d.field("data", &&*guard);
|
||||
}
|
||||
Err(TryLockError::Poisoned(err)) => {
|
||||
f.debug_struct("RwLock").field("data", &&**err.get_ref()).finish()
|
||||
d.field("data", &&**err.get_ref());
|
||||
}
|
||||
Err(TryLockError::WouldBlock) => {
|
||||
struct LockedPlaceholder;
|
||||
@ -434,10 +437,11 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
|
||||
f.write_str("<locked>")
|
||||
}
|
||||
}
|
||||
|
||||
f.debug_struct("RwLock").field("data", &LockedPlaceholder).finish()
|
||||
d.field("data", &LockedPlaceholder);
|
||||
}
|
||||
}
|
||||
d.field("poisoned", &self.poison.get());
|
||||
d.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user