//! Copied over from: //! https://github.com/tokio-rs/tokio/blob/master/tokio/tests/async_send_sync.rs #![allow(dead_code)] fn require_send(_t: &T) {} fn require_sync(_t: &T) {} fn require_unpin(_t: &T) {} struct Invalid; trait AmbiguousIfSend { fn some_item(&self) {} } impl AmbiguousIfSend<()> for T {} impl AmbiguousIfSend for T {} trait AmbiguousIfSync { fn some_item(&self) {} } impl AmbiguousIfSync<()> for T {} impl AmbiguousIfSync for T {} trait AmbiguousIfUnpin { fn some_item(&self) {} } impl AmbiguousIfUnpin<()> for T {} impl AmbiguousIfUnpin for T {} macro_rules! into_todo { ($typ:ty) => {{ let x: $typ = todo!(); x }}; } macro_rules! async_assert_fn_send { (Send & $(!)?Sync & $(!)?Unpin, $value:expr) => { require_send(&$value); }; (!Send & $(!)?Sync & $(!)?Unpin, $value:expr) => { AmbiguousIfSend::some_item(&$value); }; } macro_rules! async_assert_fn_sync { ($(!)?Send & Sync & $(!)?Unpin, $value:expr) => { require_sync(&$value); }; ($(!)?Send & !Sync & $(!)?Unpin, $value:expr) => { AmbiguousIfSync::some_item(&$value); }; } macro_rules! async_assert_fn_unpin { ($(!)?Send & $(!)?Sync & Unpin, $value:expr) => { require_unpin(&$value); }; ($(!)?Send & $(!)?Sync & !Unpin, $value:expr) => { AmbiguousIfUnpin::some_item(&$value); }; } macro_rules! async_assert_fn { ($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): $($tok:tt)*) => { #[allow(unreachable_code)] #[allow(unused_variables)] #[allow(clippy::diverging_sub_expression)] const _: fn() = || { let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* ); async_assert_fn_send!($($tok)*, f); async_assert_fn_sync!($($tok)*, f); async_assert_fn_unpin!($($tok)*, f); }; }; } macro_rules! assert_value { ($type:ty: $($tok:tt)*) => { #[allow(unreachable_code)] #[allow(unused_variables)] #[allow(clippy::diverging_sub_expression)] const _: fn() = || { let f: $type = todo!(); async_assert_fn_send!($($tok)*, f); async_assert_fn_sync!($($tok)*, f); async_assert_fn_unpin!($($tok)*, f); }; }; } assert_value!(turmoil::net::TcpListener: Send & Sync & Unpin); assert_value!(turmoil::net::TcpStream: Send & Sync & Unpin); assert_value!(turmoil::net::UdpSocket: Send & Sync & Unpin); assert_value!(turmoil::net::tcp::OwnedReadHalf: Send & Sync & Unpin); assert_value!(turmoil::net::tcp::OwnedWriteHalf: Send & Sync & Unpin); assert_value!(turmoil::net::tcp::ReuniteError: Send & Sync & Unpin); async_assert_fn!(turmoil::net::TcpListener::accept(_): Send & Sync & !Unpin);