]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sys/common/remutex.rs
Auto merge of #30641 - tsion:match-range, r=eddyb
[rust.git] / src / libstd / sys / common / remutex.rs
index 0674618396f993a21c90639617fb5502f3a9880d..31caa68c4b7ea70bcd89871e305a68076738eebf 100644 (file)
@@ -7,7 +7,9 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
-#![unstable(feature = "reentrant_mutex", reason = "new API")]
+
+#![unstable(feature = "reentrant_mutex", reason = "new API",
+            issue = "27738")]
 
 use prelude::v1::*;
 
@@ -65,7 +67,7 @@ pub fn new(t: T) -> ReentrantMutex<T> {
                 data: t,
             };
             mutex.inner.init();
-            return mutex
+            mutex
         }
     }
 
@@ -143,7 +145,7 @@ fn new(lock: &'mutex ReentrantMutex<T>)
 impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> {
     type Target = T;
 
-    fn deref<'a>(&'a self) -> &'a T {
+    fn deref(&self) -> &T {
         &self.__lock.data
     }
 }
@@ -165,7 +167,6 @@ mod tests {
     use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
     use cell::RefCell;
     use sync::Arc;
-    use boxed;
     use thread;
 
     #[test]
@@ -187,10 +188,11 @@ fn smoke() {
 
     #[test]
     fn is_mutex() {
-        let m = ReentrantMutex::new(RefCell::new(0));
+        let m = Arc::new(ReentrantMutex::new(RefCell::new(0)));
+        let m2 = m.clone();
         let lock = m.lock().unwrap();
-        let handle = thread::scoped(|| {
-            let lock = m.lock().unwrap();
+        let child = thread::spawn(move || {
+            let lock = m2.lock().unwrap();
             assert_eq!(*lock.borrow(), 4950);
         });
         for i in 0..100 {
@@ -198,21 +200,20 @@ fn is_mutex() {
             *lock.borrow_mut() += i;
         }
         drop(lock);
-        drop(handle);
+        child.join().unwrap();
     }
 
     #[test]
     fn trylock_works() {
-        let m = ReentrantMutex::new(());
-        let lock = m.try_lock().unwrap();
-        let lock2 = m.try_lock().unwrap();
-        {
-            thread::scoped(|| {
-                let lock = m.try_lock();
-                assert!(lock.is_err());
-            });
-        }
-        let lock3 = m.try_lock().unwrap();
+        let m = Arc::new(ReentrantMutex::new(()));
+        let m2 = m.clone();
+        let _lock = m.try_lock().unwrap();
+        let _lock2 = m.try_lock().unwrap();
+        thread::spawn(move || {
+            let lock = m2.try_lock();
+            assert!(lock.is_err());
+        }).join().unwrap();
+        let _lock3 = m.try_lock().unwrap();
     }
 
     pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>);
@@ -231,9 +232,8 @@ fn poison_works() {
             *lock.borrow_mut() = 1;
             let lock2 = mc.lock().unwrap();
             *lock.borrow_mut() = 2;
-            let answer = Answer(lock2);
+            let _answer = Answer(lock2);
             panic!("What the answer to my lifetimes dilemma is?");
-            drop(answer);
         }).join();
         assert!(result.is_err());
         let r = m.lock().err().unwrap().into_inner();