]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sync/mutex.rs
Change error message in rustbook
[rust.git] / src / libstd / sync / mutex.rs
index 4b62434d06894e9c78b6f40b0c1e5c1649382864..f1d264b38a0c7b18245cb46af66cfc66b351e6a5 100644 (file)
@@ -151,7 +151,8 @@ unsafe impl<T: ?Sized + Send> Sync for Mutex<T> { }
 /// // lock is unlocked here.
 /// ```
 #[unstable(feature = "static_mutex",
-           reason = "may be merged with Mutex in the future")]
+           reason = "may be merged with Mutex in the future",
+           issue = "27717")]
 pub struct StaticMutex {
     lock: sys::Mutex,
     poison: poison::Flag,
@@ -177,7 +178,8 @@ impl<'a, T: ?Sized> !marker::Send for MutexGuard<'a, T> {}
 /// Static initialization of a mutex. This constant can be used to initialize
 /// other mutex constants.
 #[unstable(feature = "static_mutex",
-           reason = "may be merged with Mutex in the future")]
+           reason = "may be merged with Mutex in the future",
+           issue = "27717")]
 pub const MUTEX_INIT: StaticMutex = StaticMutex::new();
 
 impl<T> Mutex<T> {
@@ -271,7 +273,8 @@ unsafe impl Sync for Dummy {}
 static DUMMY: Dummy = Dummy(UnsafeCell::new(()));
 
 #[unstable(feature = "static_mutex",
-           reason = "may be merged with Mutex in the future")]
+           reason = "may be merged with Mutex in the future",
+           issue = "27717")]
 impl StaticMutex {
     /// Creates a new mutex in an unlocked state ready for use.
     pub const fn new() -> StaticMutex {
@@ -331,13 +334,14 @@ fn new(lock: &'mutex StaticMutex, data: &'mutex UnsafeCell<T>)
 impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> {
     type Target = T;
 
-    fn deref<'a>(&'a self) -> &'a T {
+    fn deref(&self) -> &T {
         unsafe { &*self.__data.get() }
     }
 }
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> {
-    fn deref_mut<'a>(&'a mut self) -> &'a mut T {
+    fn deref_mut(&mut self) -> &mut T {
         unsafe { &mut *self.__data.get() }
     }
 }
@@ -369,7 +373,7 @@ mod tests {
     use sync::{Arc, Mutex, StaticMutex, Condvar};
     use thread;
 
-    struct Packet<T: Send>(Arc<(Mutex<T>, Condvar)>);
+    struct Packet<T>(Arc<(Mutex<T>, Condvar)>);
 
     unsafe impl<T: Send> Send for Packet<T> {}
     unsafe impl<T> Sync for Packet<T> {}
@@ -532,16 +536,15 @@ fn drop(&mut self) {
         assert_eq!(*lock, 2);
     }
 
-    // FIXME(#25351) needs deeply nested coercions of DST structs.
-    // #[test]
-    // fn test_mutex_unsized() {
-    //     let mutex: &Mutex<[i32]> = &Mutex::new([1, 2, 3]);
-    //     {
-    //         let b = &mut *mutex.lock().unwrap();
-    //         b[0] = 4;
-    //         b[2] = 5;
-    //     }
-    //     let comp: &[i32] = &[4, 2, 5];
-    //     assert_eq!(&*mutex.lock().unwrap(), comp);
-    // }
+    #[test]
+    fn test_mutex_unsized() {
+        let mutex: &Mutex<[i32]> = &Mutex::new([1, 2, 3]);
+        {
+            let b = &mut *mutex.lock().unwrap();
+            b[0] = 4;
+            b[2] = 5;
+        }
+        let comp: &[i32] = &[4, 2, 5];
+        assert_eq!(&*mutex.lock().unwrap(), comp);
+    }
 }