diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index a27f621e6b2ae..5c3eaa4668d28 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -10,7 +10,6 @@ use cell::UnsafeCell; use fmt; -use marker; use mem; use ops::{Deref, DerefMut}; use ptr; @@ -153,7 +152,9 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: ?Sized> !marker::Send for MutexGuard<'a, T> {} +impl<'a, T: ?Sized> !Send for MutexGuard<'a, T> { } +#[stable(feature = "mutexguard", since = "1.18.0")] +unsafe impl<'a, T: ?Sized + Sync> Sync for MutexGuard<'a, T> { } impl Mutex { /// Creates a new mutex in an unlocked state ready for use. @@ -459,9 +460,6 @@ mod tests { #[derive(Eq, PartialEq, Debug)] struct NonCopy(i32); - unsafe impl Send for Packet {} - unsafe impl Sync for Packet {} - #[test] fn smoke() { let m = Mutex::new(()); diff --git a/src/test/compile-fail/mutexguard-sync.rs b/src/test/compile-fail/mutexguard-sync.rs new file mode 100644 index 0000000000000..861714720c57a --- /dev/null +++ b/src/test/compile-fail/mutexguard-sync.rs @@ -0,0 +1,22 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// MutexGuard> must not be Sync, that would be unsound. +use std::sync::Mutex; +use std::cell::Cell; + +fn test_sync(_t: T) {} + +fn main() +{ + let m = Mutex::new(Cell::new(0i32)); + let guard = m.lock().unwrap(); + test_sync(guard); //~ ERROR the trait bound +}