Skip to content

Commit

Permalink
Loosen Send/Sync bounds on Mutex and RwLock futures
Browse files Browse the repository at this point in the history
This ensures that `Send`/`Sync` bounds for each future
match those of the value produed by the future.
  • Loading branch information
Jules-Bertholet committed Jun 14, 2023
1 parent 936e046 commit 030ca55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ pub struct Lock<'a, T: ?Sized> {
acquire_slow: Option<AcquireSlow<&'a Mutex<T>, T>>,
}

unsafe impl<T: Send + ?Sized> Send for Lock<'_, T> {}
unsafe impl<T: Sync + ?Sized> Sync for Lock<'_, T> {}

impl<'a, T: ?Sized> Unpin for Lock<'a, T> {}

impl<T: ?Sized> fmt::Debug for Lock<'_, T> {
Expand Down Expand Up @@ -319,6 +322,9 @@ enum LockArcInnards<T: ?Sized> {
Empty,
}

unsafe impl<T: Send + ?Sized> Send for LockArc<T> {}
unsafe impl<T: Sync + ?Sized> Sync for LockArc<T> {}

impl<T: ?Sized> Unpin for LockArc<T> {}

impl<T: ?Sized> fmt::Debug for LockArc<T> {
Expand Down
13 changes: 8 additions & 5 deletions src/rwlock/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct Read<'a, T: ?Sized> {
pub(super) value: *const T,
}

unsafe impl<T: Send + Sync + ?Sized> Send for Read<'_, T> {}
unsafe impl<T: Send + Sync + ?Sized> Sync for Read<'_, T> {}
unsafe impl<T: Sync + ?Sized> Send for Read<'_, T> {}
unsafe impl<T: Sync + ?Sized> Sync for Read<'_, T> {}

impl<T: ?Sized> fmt::Debug for Read<'_, T> {
#[inline]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct UpgradableRead<'a, T: ?Sized> {
}

unsafe impl<T: Send + Sync + ?Sized> Send for UpgradableRead<'_, T> {}
unsafe impl<T: Send + Sync + ?Sized> Sync for UpgradableRead<'_, T> {}
unsafe impl<T: Sync + ?Sized> Sync for UpgradableRead<'_, T> {}

impl<T: ?Sized> fmt::Debug for UpgradableRead<'_, T> {
#[inline]
Expand Down Expand Up @@ -156,8 +156,8 @@ pub struct Write<'a, T: ?Sized> {
pub(super) value: *mut T,
}

unsafe impl<T: Send + Sync + ?Sized> Send for Write<'_, T> {}
unsafe impl<T: Send + Sync + ?Sized> Sync for Write<'_, T> {}
unsafe impl<T: Send + ?Sized> Send for Write<'_, T> {}
unsafe impl<T: Sync + ?Sized> Sync for Write<'_, T> {}

impl<T: ?Sized> fmt::Debug for Write<'_, T> {
#[inline]
Expand Down Expand Up @@ -224,6 +224,9 @@ pub struct Upgrade<'a, T: ?Sized> {
pub(super) value: *mut T,
}

unsafe impl<T: Send + ?Sized> Send for Upgrade<'_, T> {}
unsafe impl<T: Sync + ?Sized> Sync for Upgrade<'_, T> {}

impl<T: ?Sized> fmt::Debug for Upgrade<'_, T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down

0 comments on commit 030ca55

Please sign in to comment.