Skip to content

Commit

Permalink
Loosen Send/Sync bounds on 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 1, 2023
1 parent 90b1a30 commit 76430c6
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.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ pub struct Read<'a, T: ?Sized> {
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> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -360,7 +360,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> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -393,8 +393,8 @@ pub struct Write<'a, T: ?Sized> {
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> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -623,6 +623,9 @@ pub struct Upgrade<'a, T: ?Sized> {
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> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Upgrade").finish()
Expand Down

0 comments on commit 76430c6

Please sign in to comment.