Skip to content

Commit

Permalink
Fix Sync impl of FuturesUnordered
Browse files Browse the repository at this point in the history
Fixes #2786
  • Loading branch information
taiki-e committed Oct 26, 2023
1 parent de8e42e commit 9368941
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion futures-util/src/stream/futures_unordered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct FuturesUnordered<Fut> {
}

unsafe impl<Fut: Send> Send for FuturesUnordered<Fut> {}
unsafe impl<Fut: Sync> Sync for FuturesUnordered<Fut> {}
unsafe impl<Fut: Send + Sync> Sync for FuturesUnordered<Fut> {}
impl<Fut> Unpin for FuturesUnordered<Fut> {}

impl Spawn for FuturesUnordered<FutureObj<'_, ()>> {
Expand Down
43 changes: 25 additions & 18 deletions futures/tests/auto_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub type SendFuture<T = *const ()> = Pin<Box<dyn Future<Output = T> + Send>>;
pub type SendTryFuture<T = *const (), E = *const ()> = SendFuture<Result<T, E>>;
pub type SyncFuture<T = *const ()> = Pin<Box<dyn Future<Output = T> + Sync>>;
pub type SyncTryFuture<T = *const (), E = *const ()> = SyncFuture<Result<T, E>>;
pub type SendSyncFuture<T = *const ()> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
pub type SendSyncTryFuture<T = *const (), E = *const ()> = SendSyncFuture<Result<T, E>>;
pub type UnpinFuture<T = PhantomPinned> = LocalFuture<T>;
pub type UnpinTryFuture<T = PhantomPinned, E = PhantomPinned> = UnpinFuture<Result<T, E>>;
pub struct PinnedFuture<T = PhantomPinned>(PhantomPinned, PhantomData<T>);
Expand All @@ -36,6 +38,8 @@ pub type SendStream<T = *const ()> = Pin<Box<dyn Stream<Item = T> + Send>>;
pub type SendTryStream<T = *const (), E = *const ()> = SendStream<Result<T, E>>;
pub type SyncStream<T = *const ()> = Pin<Box<dyn Stream<Item = T> + Sync>>;
pub type SyncTryStream<T = *const (), E = *const ()> = SyncStream<Result<T, E>>;
pub type SendSyncStream<T = *const ()> = Pin<Box<dyn Stream<Item = T> + Send + Sync>>;
pub type SendSyncTryStream<T = *const (), E = *const ()> = SendSyncStream<Result<T, E>>;
pub type UnpinStream<T = PhantomPinned> = LocalStream<T>;
pub type UnpinTryStream<T = PhantomPinned, E = PhantomPinned> = UnpinStream<Result<T, E>>;
pub struct PinnedStream<T = PhantomPinned>(PhantomPinned, PhantomData<T>);
Expand Down Expand Up @@ -366,9 +370,10 @@ pub mod future {
assert_impl!(JoinAll<SendFuture<()>>: Send);
assert_not_impl!(JoinAll<LocalFuture>: Send);
assert_not_impl!(JoinAll<SendFuture>: Send);
assert_impl!(JoinAll<SyncFuture<()>>: Sync);
assert_not_impl!(JoinAll<LocalFuture>: Sync);
assert_not_impl!(JoinAll<SyncFuture>: Sync);
assert_impl!(JoinAll<SendSyncFuture<()>>: Sync);
assert_not_impl!(JoinAll<SendFuture<()>>: Sync);
assert_not_impl!(JoinAll<SyncFuture<()>>: Sync);
assert_not_impl!(JoinAll<SendSyncFuture>: Sync);
assert_impl!(JoinAll<PinnedFuture>: Unpin);

assert_impl!(Lazy<()>: Send);
Expand Down Expand Up @@ -580,9 +585,10 @@ pub mod future {
assert_impl!(TryJoinAll<SendTryFuture<(), ()>>: Send);
assert_not_impl!(TryJoinAll<LocalTryFuture>: Send);
assert_not_impl!(TryJoinAll<SendTryFuture>: Send);
assert_impl!(TryJoinAll<SyncTryFuture<(), ()>>: Sync);
assert_not_impl!(TryJoinAll<LocalTryFuture>: Sync);
assert_not_impl!(TryJoinAll<SyncTryFuture>: Sync);
assert_impl!(TryJoinAll<SendSyncTryFuture<(), ()>>: Sync);
assert_not_impl!(TryJoinAll<SendTryFuture<(), ()>>: Sync);
assert_not_impl!(TryJoinAll<SyncTryFuture<(), ()>>: Sync);
assert_not_impl!(TryJoinAll<SendSyncTryFuture>: Sync);
assert_impl!(TryJoinAll<PinnedTryFuture>: Unpin);

assert_impl!(TrySelect<SendFuture, SendFuture>: Send);
Expand Down Expand Up @@ -1119,10 +1125,9 @@ pub mod stream {
assert_not_impl!(Buffered<SendStream<SendFuture>>: Send);
assert_not_impl!(Buffered<SendStream<LocalFuture>>: Send);
assert_not_impl!(Buffered<LocalStream<SendFuture<()>>>: Send);
assert_impl!(Buffered<SyncStream<SyncFuture<()>>>: Sync);
assert_not_impl!(Buffered<SyncStream<SyncFuture>>: Sync);
assert_not_impl!(Buffered<SyncStream<LocalFuture>>: Sync);
assert_not_impl!(Buffered<LocalStream<SyncFuture<()>>>: Sync);
assert_impl!(Buffered<SyncStream<SendSyncFuture<()>>>: Sync);
assert_not_impl!(Buffered<SyncStream<SyncFuture<()>>>: Sync);
assert_not_impl!(Buffered<LocalStream<SendSyncFuture<()>>>: Sync);
assert_impl!(Buffered<UnpinStream<PinnedFuture>>: Unpin);
assert_not_impl!(Buffered<PinnedStream<PinnedFuture>>: Unpin);

Expand Down Expand Up @@ -1316,9 +1321,10 @@ pub mod stream {
assert_impl!(FuturesOrdered<SendFuture<()>>: Send);
assert_not_impl!(FuturesOrdered<SendFuture>: Send);
assert_not_impl!(FuturesOrdered<SendFuture>: Send);
assert_impl!(FuturesOrdered<SyncFuture<()>>: Sync);
assert_not_impl!(FuturesOrdered<LocalFuture<()>>: Sync);
assert_not_impl!(FuturesOrdered<LocalFuture<()>>: Sync);
assert_impl!(FuturesOrdered<SendSyncFuture<()>>: Sync);
assert_not_impl!(FuturesOrdered<SyncFuture<()>>: Sync);
assert_not_impl!(FuturesOrdered<SendFuture<()>>: Sync);
assert_not_impl!(FuturesOrdered<SendSyncFuture>: Sync);
assert_impl!(FuturesOrdered<PinnedFuture>: Unpin);

assert_impl!(FuturesUnordered<()>: Send);
Expand Down Expand Up @@ -1660,11 +1666,12 @@ pub mod stream {
assert_not_impl!(TryBuffered<SendTryStream<SendTryFuture<(), *const ()>>>: Send);
assert_not_impl!(TryBuffered<SendTryStream<LocalTryFuture<(), ()>>>: Send);
assert_not_impl!(TryBuffered<LocalTryStream<SendTryFuture<(), ()>>>: Send);
assert_impl!(TryBuffered<SyncTryStream<SyncTryFuture<(), ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SyncTryFuture<*const (), ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SyncTryFuture<(), *const ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<LocalTryFuture<(), ()>>>: Sync);
assert_not_impl!(TryBuffered<LocalTryStream<SyncTryFuture<(), ()>>>: Sync);
assert_impl!(TryBuffered<SyncTryStream<SendSyncTryFuture<(), ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SendSyncTryFuture<*const (), ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SendSyncTryFuture<(), *const ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SendTryFuture<(), ()>>>: Sync);
assert_not_impl!(TryBuffered<SyncTryStream<SyncTryFuture<(), ()>>>: Sync);
assert_not_impl!(TryBuffered<LocalTryStream<SendSyncTryFuture<(), ()>>>: Sync);
assert_impl!(TryBuffered<UnpinTryStream<PinnedTryFuture>>: Unpin);
assert_not_impl!(TryBuffered<PinnedTryStream<UnpinTryFuture>>: Unpin);

Expand Down

0 comments on commit 9368941

Please sign in to comment.