/// // 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,
/// 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> {
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 {
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() }
}
}
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);
+ }
}