1 use std::rc::Rc;
2
3 #[allow(dead_code)]
4 type BoxStream<T> = std::pin::Pin<Box<dyn tokio_stream::Stream<Item = T>>>;
5
6 #[allow(dead_code)]
require_send<T: Send>(_t: &T)7 fn require_send<T: Send>(_t: &T) {}
8 #[allow(dead_code)]
require_sync<T: Sync>(_t: &T)9 fn require_sync<T: Sync>(_t: &T) {}
10 #[allow(dead_code)]
require_unpin<T: Unpin>(_t: &T)11 fn require_unpin<T: Unpin>(_t: &T) {}
12
13 #[allow(dead_code)]
14 struct Invalid;
15
16 trait AmbiguousIfSend<A> {
some_item(&self)17 fn some_item(&self) {}
18 }
19 impl<T: ?Sized> AmbiguousIfSend<()> for T {}
20 impl<T: ?Sized + Send> AmbiguousIfSend<Invalid> for T {}
21
22 trait AmbiguousIfSync<A> {
some_item(&self)23 fn some_item(&self) {}
24 }
25 impl<T: ?Sized> AmbiguousIfSync<()> for T {}
26 impl<T: ?Sized + Sync> AmbiguousIfSync<Invalid> for T {}
27
28 trait AmbiguousIfUnpin<A> {
some_item(&self)29 fn some_item(&self) {}
30 }
31 impl<T: ?Sized> AmbiguousIfUnpin<()> for T {}
32 impl<T: ?Sized + Unpin> AmbiguousIfUnpin<Invalid> for T {}
33
34 macro_rules! into_todo {
35 ($typ:ty) => {{
36 let x: $typ = todo!();
37 x
38 }};
39 }
40
41 macro_rules! async_assert_fn {
42 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): Send & Sync) => {
43 #[allow(unreachable_code)]
44 #[allow(unused_variables)]
45 const _: fn() = || {
46 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
47 require_send(&f);
48 require_sync(&f);
49 };
50 };
51 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): Send & !Sync) => {
52 #[allow(unreachable_code)]
53 #[allow(unused_variables)]
54 const _: fn() = || {
55 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
56 require_send(&f);
57 AmbiguousIfSync::some_item(&f);
58 };
59 };
60 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): !Send & Sync) => {
61 #[allow(unreachable_code)]
62 #[allow(unused_variables)]
63 const _: fn() = || {
64 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
65 AmbiguousIfSend::some_item(&f);
66 require_sync(&f);
67 };
68 };
69 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): !Send & !Sync) => {
70 #[allow(unreachable_code)]
71 #[allow(unused_variables)]
72 const _: fn() = || {
73 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
74 AmbiguousIfSend::some_item(&f);
75 AmbiguousIfSync::some_item(&f);
76 };
77 };
78 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): !Unpin) => {
79 #[allow(unreachable_code)]
80 #[allow(unused_variables)]
81 const _: fn() = || {
82 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
83 AmbiguousIfUnpin::some_item(&f);
84 };
85 };
86 ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): Unpin) => {
87 #[allow(unreachable_code)]
88 #[allow(unused_variables)]
89 const _: fn() = || {
90 let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
91 require_unpin(&f);
92 };
93 };
94 }
95
96 async_assert_fn!(tokio_stream::empty<Rc<u8>>(): Send & Sync);
97 async_assert_fn!(tokio_stream::pending<Rc<u8>>(): Send & Sync);
98 async_assert_fn!(tokio_stream::iter(std::vec::IntoIter<u8>): Send & Sync);
99
100 async_assert_fn!(tokio_stream::StreamExt::next(&mut BoxStream<()>): !Unpin);
101 async_assert_fn!(tokio_stream::StreamExt::try_next(&mut BoxStream<Result<(), ()>>): !Unpin);
102 async_assert_fn!(tokio_stream::StreamExt::all(&mut BoxStream<()>, fn(())->bool): !Unpin);
103 async_assert_fn!(tokio_stream::StreamExt::any(&mut BoxStream<()>, fn(())->bool): !Unpin);
104 async_assert_fn!(tokio_stream::StreamExt::fold(&mut BoxStream<()>, (), fn((), ())->()): !Unpin);
105 async_assert_fn!(tokio_stream::StreamExt::collect<Vec<()>>(&mut BoxStream<()>): !Unpin);
106