File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,13 @@ pub struct Weak<T> {
139139unsafe impl < T : Sync + Send > Send for Weak < T > { }
140140unsafe impl < T : Sync + Send > Sync for Weak < T > { }
141141
142+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
143+ impl < T : fmt:: Debug > fmt:: Debug for Weak < T > {
144+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
145+ write ! ( f, "(Weak)" )
146+ }
147+ }
148+
142149struct ArcInner < T > {
143150 strong : atomic:: AtomicUsize ,
144151 weak : atomic:: AtomicUsize ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use marker;
1515use ops:: { Deref , DerefMut } ;
1616use sync:: poison:: { self , TryLockError , TryLockResult , LockResult } ;
1717use sys_common:: mutex as sys;
18+ use fmt;
1819
1920/// A mutual exclusion primitive useful for protecting shared data
2021///
@@ -250,6 +251,19 @@ impl<T: Send> Drop for Mutex<T> {
250251 }
251252}
252253
254+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
255+ impl < T : fmt:: Debug + Send + ' static > fmt:: Debug for Mutex < T > {
256+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
257+ match self . try_lock ( ) {
258+ Ok ( guard) => write ! ( f, "Mutex {{ data: {:?} }}" , * guard) ,
259+ Err ( TryLockError :: Poisoned ( err) ) => {
260+ write ! ( f, "Mutex {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
261+ } ,
262+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "Mutex {{ <locked> }}" )
263+ }
264+ }
265+ }
266+
253267struct Dummy ( UnsafeCell < ( ) > ) ;
254268unsafe impl Sync for Dummy { }
255269static DUMMY : Dummy = Dummy ( UnsafeCell { value : ( ) } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use marker;
1515use ops:: { Deref , DerefMut } ;
1616use sync:: poison:: { self , LockResult , TryLockError , TryLockResult } ;
1717use sys_common:: rwlock as sys;
18+ use fmt;
1819
1920/// A reader-writer lock
2021///
@@ -255,6 +256,19 @@ impl<T> Drop for RwLock<T> {
255256 }
256257}
257258
259+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
260+ impl < T : fmt:: Debug + Send + Sync > fmt:: Debug for RwLock < T > {
261+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
262+ match self . try_read ( ) {
263+ Ok ( guard) => write ! ( f, "RwLock {{ data: {:?} }}" , * guard) ,
264+ Err ( TryLockError :: Poisoned ( err) ) => {
265+ write ! ( f, "RwLock {{ data: Poisoned({:?}) }}" , * * err. get_ref( ) )
266+ } ,
267+ Err ( TryLockError :: WouldBlock ) => write ! ( f, "RwLock {{ <locked> }}" )
268+ }
269+ }
270+ }
271+
258272struct Dummy ( UnsafeCell < ( ) > ) ;
259273unsafe impl Sync for Dummy { }
260274static DUMMY : Dummy = Dummy ( UnsafeCell { value : ( ) } ) ;
You can’t perform that action at this time.
0 commit comments