From 4c00d6212aa5fa56d16cc8a1774ad908d10522bd Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 17 Nov 2020 22:57:51 +0000 Subject: [PATCH] Fix bounds on Send and Sync impls for lock guards Fixes #258 Fixes #259 --- lock_api/src/lib.rs | 2 ++ lock_api/src/mutex.rs | 2 +- lock_api/src/rwlock.rs | 8 ++------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lock_api/src/lib.rs b/lock_api/src/lib.rs index de724422..d9097a39 100644 --- a/lock_api/src/lib.rs +++ b/lock_api/src/lib.rs @@ -99,6 +99,8 @@ pub struct GuardSend(()); /// Marker type which indicates that the Guard type for a lock is not `Send`. pub struct GuardNoSend(*mut ()); +unsafe impl Sync for GuardNoSend {} + mod mutex; pub use crate::mutex::*; diff --git a/lock_api/src/mutex.rs b/lock_api/src/mutex.rs index e435d8ae..aded96d1 100644 --- a/lock_api/src/mutex.rs +++ b/lock_api/src/mutex.rs @@ -601,7 +601,7 @@ unsafe impl<'a, R: RawMutex + Sync + 'a, T: ?Sized + Sync + 'a> Sync for MappedMutexGuard<'a, R, T> { } -unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Send for MappedMutexGuard<'a, R, T> where +unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + Send + 'a> Send for MappedMutexGuard<'a, R, T> where R::GuardMarker: Send { } diff --git a/lock_api/src/rwlock.rs b/lock_api/src/rwlock.rs index a25c2f45..e97de980 100644 --- a/lock_api/src/rwlock.rs +++ b/lock_api/src/rwlock.rs @@ -875,8 +875,6 @@ pub struct RwLockReadGuard<'a, R: RawRwLock, T: ?Sized> { marker: PhantomData<(&'a T, R::GuardMarker)>, } -unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Sync + 'a> Sync for RwLockReadGuard<'a, R, T> {} - impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockReadGuard<'a, R, T> { /// Returns a reference to the original reader-writer lock object. pub fn rwlock(s: &Self) -> &'a RwLock { @@ -1051,8 +1049,6 @@ pub struct RwLockWriteGuard<'a, R: RawRwLock, T: ?Sized> { marker: PhantomData<(&'a mut T, R::GuardMarker)>, } -unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Sync + 'a> Sync for RwLockWriteGuard<'a, R, T> {} - impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> RwLockWriteGuard<'a, R, T> { /// Returns a reference to the original reader-writer lock object. pub fn rwlock(s: &Self) -> &'a RwLock { @@ -1514,7 +1510,7 @@ pub struct MappedRwLockReadGuard<'a, R: RawRwLock, T: ?Sized> { } unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Sync + 'a> Sync for MappedRwLockReadGuard<'a, R, T> {} -unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Send for MappedRwLockReadGuard<'a, R, T> where +unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Sync + 'a> Send for MappedRwLockReadGuard<'a, R, T> where R::GuardMarker: Send { } @@ -1652,7 +1648,7 @@ unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Sync + 'a> Sync for MappedRwLockWriteGuard<'a, R, T> { } -unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + 'a> Send for MappedRwLockWriteGuard<'a, R, T> where +unsafe impl<'a, R: RawRwLock + 'a, T: ?Sized + Send + 'a> Send for MappedRwLockWriteGuard<'a, R, T> where R::GuardMarker: Send { }