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