From 6073c6c78d2caf0da2ce24407dd97384a2a3cdd1 Mon Sep 17 00:00:00 2001 From: Benjamin Lerman Date: Fri, 29 Apr 2022 12:05:24 +0200 Subject: [PATCH] Fix Target for Deref of stdsync::TracingMutexGuard --- src/stdsync.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/stdsync.rs b/src/stdsync.rs index 462e697..26b92f6 100644 --- a/src/stdsync.rs +++ b/src/stdsync.rs @@ -195,7 +195,7 @@ impl From for TracingMutex { } impl<'a, T> Deref for TracingMutexGuard<'a, T> { - type Target = MutexGuard<'a, T>; + type Target = T; fn deref(&self) -> &Self::Target { &self.inner @@ -413,7 +413,12 @@ mod tests { #[test] fn test_mutex_usage() { - let mutex = Arc::new(TracingMutex::new(())); + let mutex = Arc::new(TracingMutex::new((0))); + + assert_eq!(*mutex.lock().unwrap(), 0); + *mutex.lock().unwrap() = 1; + assert_eq!(*mutex.lock().unwrap(), 1); + let mutex_clone = mutex.clone(); let _guard = mutex.lock().unwrap(); @@ -430,7 +435,14 @@ mod tests { #[test] fn test_rwlock_usage() { - let rwlock = Arc::new(TracingRwLock::new(())); + let rwlock = Arc::new(TracingRwLock::new((0))); + + assert_eq!(*rwlock.read().unwrap(), 0); + assert_eq!(*rwlock.write().unwrap(), 0); + *rwlock.write().unwrap() = 1; + assert_eq!(*rwlock.read().unwrap(), 1); + assert_eq!(*rwlock.write().unwrap(), 1); + let rwlock_clone = rwlock.clone(); let _read_lock = rwlock.read().unwrap();