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`).
This commit is contained in:
Huon Wilson 2015-03-08 22:01:01 +11:00
parent 35275076f5
commit 25d070f228
2 changed files with 7 additions and 5 deletions

View File

@ -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 @@ impl<'a, T> !marker::Send for MutexGuard<'a, T> {}
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 @@ pub fn is_poisoned(&self) -> bool {
#[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 @@ fn drop(&mut self) {
}
#[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),

View File

@ -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 @@ fn drop(&mut self) {
}
#[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),