about summary refs log tree commit diff
path: root/src/libstd/sync
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2015-03-08 22:01:01 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2015-03-08 22:01:01 +1100
commit25d070f228a101a806165a434b150a59a54f08ba (patch)
tree3f6b4510213965d22c41f8787ff74dbbbfebdf08 /src/libstd/sync
parent35275076f52d53c3dcd9dee85d92a2059a663225 (diff)
downloadrust-25d070f228a101a806165a434b150a59a54f08ba.tar.gz
rust-25d070f228a101a806165a434b150a59a54f08ba.zip
Remove unneeded `Send`/`Sync` bounds from `Mutex`/`RwLock`.
The requirements `T: Send` and `T: Send + Sync` for `Mutex` and `RwLock`
respectively only matter if those types are shared/sent across thread
boundaries, and that is adequately controlled by the impls of
`Send`/`Sync` for them. If `T` doesn't satisfy the bounds, then
the types cannot cross thread boundaries and so everything is still
safe (the two types just act like an expensive `RefCell`).
Diffstat (limited to 'src/libstd/sync')
-rw-r--r--src/libstd/sync/mutex.rs8
-rw-r--r--src/libstd/sync/rwlock.rs4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index 6f0febd61e8..7b5076acbca 100644
--- a/src/libstd/sync/mutex.rs
+++ b/src/libstd/sync/mutex.rs
@@ -121,6 +121,8 @@ pub struct Mutex<T> {
     data: UnsafeCell<T>,
 }
 
+// these are the only places where `T: Send` matters; all other
+// functionality works fine on a single thread.
 unsafe impl<T: Send> Send for Mutex<T> { }
 
 unsafe impl<T: Send> Sync for Mutex<T> { }
@@ -179,7 +181,7 @@ pub const MUTEX_INIT: StaticMutex = StaticMutex {
     poison: poison::FLAG_INIT,
 };
 
-impl<T: Send> Mutex<T> {
+impl<T> Mutex<T> {
     /// Creates a new mutex in an unlocked state ready for use.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn new(t: T) -> Mutex<T> {
@@ -242,7 +244,7 @@ impl<T: Send> Mutex<T> {
 
 #[unsafe_destructor]
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: Send> Drop for Mutex<T> {
+impl<T> Drop for Mutex<T> {
     fn drop(&mut self) {
         // This is actually safe b/c we know that there is no further usage of
         // this mutex (it's up to the user to arrange for a mutex to get
@@ -252,7 +254,7 @@ impl<T: Send> Drop for Mutex<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: fmt::Debug + Send + 'static> fmt::Debug for Mutex<T> {
+impl<T: fmt::Debug + 'static> fmt::Debug for Mutex<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self.try_lock() {
             Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", *guard),
diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs
index e9ff6c0bf9d..d32eae15a1b 100644
--- a/src/libstd/sync/rwlock.rs
+++ b/src/libstd/sync/rwlock.rs
@@ -129,7 +129,7 @@ pub struct RwLockWriteGuard<'a, T: 'a> {
 
 impl<'a, T> !marker::Send for RwLockWriteGuard<'a, T> {}
 
-impl<T: Send + Sync> RwLock<T> {
+impl<T> RwLock<T> {
     /// Creates a new instance of an `RwLock<T>` which is unlocked.
     ///
     /// # Examples
@@ -257,7 +257,7 @@ impl<T> Drop for RwLock<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: fmt::Debug + Send + Sync> fmt::Debug for RwLock<T> {
+impl<T: fmt::Debug> fmt::Debug for RwLock<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self.try_read() {
             Ok(guard) => write!(f, "RwLock {{ data: {:?} }}", *guard),