X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibstd%2Fsync%2Fmutex.rs;h=f1d264b38a0c7b18245cb46af66cfc66b351e6a5;hb=a3f9fc69d6e9fe3e3c3fd0f1e69ddd9733a2e05b;hp=4b62434d06894e9c78b6f40b0c1e5c1649382864;hpb=efdbc0ec7e9bd8d2dadbe78b003fd7facf2a7aae;p=rust.git diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 4b62434d068..f1d264b38a0 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -151,7 +151,8 @@ unsafe impl Sync for Mutex { } /// // 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 Mutex { @@ -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) 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(Arc<(Mutex, Condvar)>); + struct Packet(Arc<(Mutex, Condvar)>); unsafe impl Send for Packet {} unsafe impl Sync for Packet {} @@ -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); + } }