Auto merge of #22573 - nwin:impl-debug-rwlock-weak, r=Manishearth
Implements `Debug` for `RwLock` and `arc::Weak` in the same way it is implemented for `rc::Weak` (basically copy & paste). The lack of this implementation prevents the automatic implementation of `Debug` for structs containing members of these types.
This commit is contained in:
commit
bd0d8e47e5
3 changed files with 35 additions and 0 deletions
|
@ -139,6 +139,13 @@ pub struct Weak<T> {
|
||||||
unsafe impl<T: Sync + Send> Send for Weak<T> { }
|
unsafe impl<T: Sync + Send> Send for Weak<T> { }
|
||||||
unsafe impl<T: Sync + Send> Sync for Weak<T> { }
|
unsafe impl<T: Sync + Send> Sync for Weak<T> { }
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T: fmt::Debug> fmt::Debug for Weak<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "(Weak)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ArcInner<T> {
|
struct ArcInner<T> {
|
||||||
strong: atomic::AtomicUsize,
|
strong: atomic::AtomicUsize,
|
||||||
weak: atomic::AtomicUsize,
|
weak: atomic::AtomicUsize,
|
||||||
|
|
|
@ -15,6 +15,7 @@ use marker;
|
||||||
use ops::{Deref, DerefMut};
|
use ops::{Deref, DerefMut};
|
||||||
use sync::poison::{self, TryLockError, TryLockResult, LockResult};
|
use sync::poison::{self, TryLockError, TryLockResult, LockResult};
|
||||||
use sys_common::mutex as sys;
|
use sys_common::mutex as sys;
|
||||||
|
use fmt;
|
||||||
|
|
||||||
/// A mutual exclusion primitive useful for protecting shared data
|
/// A mutual exclusion primitive useful for protecting shared data
|
||||||
///
|
///
|
||||||
|
@ -250,6 +251,19 @@ impl<T: Send> Drop for Mutex<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T: fmt::Debug + Send + 'static> fmt::Debug for Mutex<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self.try_lock() {
|
||||||
|
Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", *guard),
|
||||||
|
Err(TryLockError::Poisoned(err)) => {
|
||||||
|
write!(f, "Mutex {{ data: Poisoned({:?}) }}", **err.get_ref())
|
||||||
|
},
|
||||||
|
Err(TryLockError::WouldBlock) => write!(f, "Mutex {{ <locked> }}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Dummy(UnsafeCell<()>);
|
struct Dummy(UnsafeCell<()>);
|
||||||
unsafe impl Sync for Dummy {}
|
unsafe impl Sync for Dummy {}
|
||||||
static DUMMY: Dummy = Dummy(UnsafeCell { value: () });
|
static DUMMY: Dummy = Dummy(UnsafeCell { value: () });
|
||||||
|
|
|
@ -15,6 +15,7 @@ use marker;
|
||||||
use ops::{Deref, DerefMut};
|
use ops::{Deref, DerefMut};
|
||||||
use sync::poison::{self, LockResult, TryLockError, TryLockResult};
|
use sync::poison::{self, LockResult, TryLockError, TryLockResult};
|
||||||
use sys_common::rwlock as sys;
|
use sys_common::rwlock as sys;
|
||||||
|
use fmt;
|
||||||
|
|
||||||
/// A reader-writer lock
|
/// A reader-writer lock
|
||||||
///
|
///
|
||||||
|
@ -255,6 +256,19 @@ impl<T> Drop for RwLock<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T: fmt::Debug + Send + Sync> fmt::Debug for RwLock<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self.try_read() {
|
||||||
|
Ok(guard) => write!(f, "RwLock {{ data: {:?} }}", *guard),
|
||||||
|
Err(TryLockError::Poisoned(err)) => {
|
||||||
|
write!(f, "RwLock {{ data: Poisoned({:?}) }}", **err.get_ref())
|
||||||
|
},
|
||||||
|
Err(TryLockError::WouldBlock) => write!(f, "RwLock {{ <locked> }}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Dummy(UnsafeCell<()>);
|
struct Dummy(UnsafeCell<()>);
|
||||||
unsafe impl Sync for Dummy {}
|
unsafe impl Sync for Dummy {}
|
||||||
static DUMMY: Dummy = Dummy(UnsafeCell { value: () });
|
static DUMMY: Dummy = Dummy(UnsafeCell { value: () });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue