1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use std::cell::Cell;
use std::io::Cursor;
use std::net::SocketAddr;
use std::rc::Rc;
use tokio::net::TcpStream;
use tokio::time::{Duration, Instant};
#[allow(dead_code)]
type BoxFutureSync<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + Sync>>;
#[allow(dead_code)]
type BoxFutureSend<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send>>;
#[allow(dead_code)]
type BoxFuture<T> = std::pin::Pin<Box<dyn std::future::Future<Output = T>>>;
#[allow(dead_code)]
fn require_send<T: Send>(_t: &T) {}
#[allow(dead_code)]
fn require_sync<T: Sync>(_t: &T) {}
#[allow(dead_code)]
struct Invalid;
trait AmbiguousIfSend<A> {
fn some_item(&self) {}
}
impl<T: ?Sized> AmbiguousIfSend<()> for T {}
impl<T: ?Sized + Send> AmbiguousIfSend<Invalid> for T {}
trait AmbiguousIfSync<A> {
fn some_item(&self) {}
}
impl<T: ?Sized> AmbiguousIfSync<()> for T {}
impl<T: ?Sized + Sync> AmbiguousIfSync<Invalid> for T {}
macro_rules! into_todo {
($typ:ty) => {{
let x: $typ = todo!();
x
}};
}
macro_rules! assert_value {
($type:ty: Send & Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f: $type = todo!();
require_send(&f);
require_sync(&f);
};
};
($type:ty: !Send & Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f: $type = todo!();
AmbiguousIfSend::some_item(&f);
require_sync(&f);
};
};
($type:ty: Send & !Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f: $type = todo!();
require_send(&f);
AmbiguousIfSync::some_item(&f);
};
};
($type:ty: !Send & !Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f: $type = todo!();
AmbiguousIfSend::some_item(&f);
AmbiguousIfSync::some_item(&f);
};
};
}
macro_rules! async_assert_fn {
($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): Send & Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
require_send(&f);
require_sync(&f);
};
};
($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): Send & !Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
require_send(&f);
AmbiguousIfSync::some_item(&f);
};
};
($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): !Send & Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
AmbiguousIfSend::some_item(&f);
require_sync(&f);
};
};
($($f:ident $(< $($generic:ty),* > )? )::+($($arg:ty),*): !Send & !Sync) => {
#[allow(unreachable_code)]
#[allow(unused_variables)]
const _: fn() = || {
let f = $($f $(::<$($generic),*>)? )::+( $( into_todo!($arg) ),* );
AmbiguousIfSend::some_item(&f);
AmbiguousIfSync::some_item(&f);
};
};
}
async_assert_fn!(tokio::io::copy(&mut TcpStream, &mut TcpStream): Send & Sync);
async_assert_fn!(tokio::io::empty(): Send & Sync);
async_assert_fn!(tokio::io::repeat(u8): Send & Sync);
async_assert_fn!(tokio::io::sink(): Send & Sync);
async_assert_fn!(tokio::io::split(TcpStream): Send & Sync);
async_assert_fn!(tokio::io::stderr(): Send & Sync);
async_assert_fn!(tokio::io::stdin(): Send & Sync);
async_assert_fn!(tokio::io::stdout(): Send & Sync);
async_assert_fn!(tokio::io::Split<Cursor<Vec<u8>>>::next_segment(_): Send & Sync);
async_assert_fn!(tokio::fs::canonicalize(&str): Send & Sync);
async_assert_fn!(tokio::fs::copy(&str, &str): Send & Sync);
async_assert_fn!(tokio::fs::create_dir(&str): Send & Sync);
async_assert_fn!(tokio::fs::create_dir_all(&str): Send & Sync);
async_assert_fn!(tokio::fs::hard_link(&str, &str): Send & Sync);
async_assert_fn!(tokio::fs::metadata(&str): Send & Sync);
async_assert_fn!(tokio::fs::read(&str): Send & Sync);
async_assert_fn!(tokio::fs::read_dir(&str): Send & Sync);
async_assert_fn!(tokio::fs::read_link(&str): Send & Sync);
async_assert_fn!(tokio::fs::read_to_string(&str): Send & Sync);
async_assert_fn!(tokio::fs::remove_dir(&str): Send & Sync);
async_assert_fn!(tokio::fs::remove_dir_all(&str): Send & Sync);
async_assert_fn!(tokio::fs::remove_file(&str): Send & Sync);
async_assert_fn!(tokio::fs::rename(&str, &str): Send & Sync);
async_assert_fn!(tokio::fs::set_permissions(&str, std::fs::Permissions): Send & Sync);
async_assert_fn!(tokio::fs::symlink_metadata(&str): Send & Sync);
async_assert_fn!(tokio::fs::write(&str, Vec<u8>): Send & Sync);
async_assert_fn!(tokio::fs::ReadDir::next_entry(_): Send & Sync);
async_assert_fn!(tokio::fs::OpenOptions::open(_, &str): Send & Sync);
async_assert_fn!(tokio::fs::DirEntry::metadata(_): Send & Sync);
async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync);
async_assert_fn!(tokio::fs::File::open(&str): Send & Sync);
async_assert_fn!(tokio::fs::File::create(&str): Send & Sync);
async_assert_fn!(tokio::fs::File::seek(_, std::io::SeekFrom): Send & Sync);
async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync);
async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync);
async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync);
async_assert_fn!(tokio::fs::File::metadata(_): Send & Sync);
async_assert_fn!(tokio::fs::File::try_clone(_): Send & Sync);
async_assert_fn!(tokio::fs::File::into_std(_): Send & Sync);
async_assert_fn!(tokio::fs::File::set_permissions(_, std::fs::Permissions): Send & Sync);
async_assert_fn!(tokio::net::lookup_host(SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::TcpListener::bind(SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::TcpListener::accept(_): Send & Sync);
async_assert_fn!(tokio::net::TcpStream::connect(SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::TcpStream::peek(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::tcp::ReadHalf::peek(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::bind(SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::connect(_, SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::send(_, &[u8]): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::recv(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::send_to(_, &[u8], SocketAddr): Send & Sync);
async_assert_fn!(tokio::net::UdpSocket::recv_from(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::udp::RecvHalf::recv(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::udp::RecvHalf::recv_from(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::udp::SendHalf::send(_, &[u8]): Send & Sync);
async_assert_fn!(tokio::net::udp::SendHalf::send_to(_, &[u8], &SocketAddr): Send & Sync);
#[cfg(unix)]
mod unix_datagram {
use super::*;
async_assert_fn!(tokio::net::UnixListener::bind(&str): Send & Sync);
async_assert_fn!(tokio::net::UnixListener::accept(_): Send & Sync);
async_assert_fn!(tokio::net::UnixDatagram::send(_, &[u8]): Send & Sync);
async_assert_fn!(tokio::net::UnixDatagram::recv(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::UnixDatagram::send_to(_, &[u8], &str): Send & Sync);
async_assert_fn!(tokio::net::UnixDatagram::recv_from(_, &mut [u8]): Send & Sync);
async_assert_fn!(tokio::net::UnixStream::connect(&str): Send & Sync);
}
async_assert_fn!(tokio::process::Child::wait_with_output(_): Send & Sync);
async_assert_fn!(tokio::signal::ctrl_c(): Send & Sync);
#[cfg(unix)]
async_assert_fn!(tokio::signal::unix::Signal::recv(_): Send & Sync);
async_assert_fn!(tokio::stream::empty<Rc<u8>>(): Send & Sync);
async_assert_fn!(tokio::stream::pending<Rc<u8>>(): Send & Sync);
async_assert_fn!(tokio::stream::iter(std::vec::IntoIter<u8>): Send & Sync);
async_assert_fn!(tokio::sync::Barrier::wait(_): Send & Sync);
async_assert_fn!(tokio::sync::Mutex<u8>::lock(_): Send & Sync);
async_assert_fn!(tokio::sync::Mutex<Cell<u8>>::lock(_): Send & Sync);
async_assert_fn!(tokio::sync::Mutex<Rc<u8>>::lock(_): !Send & !Sync);
async_assert_fn!(tokio::sync::Mutex<u8>::lock_owned(_): Send & Sync);
async_assert_fn!(tokio::sync::Mutex<Cell<u8>>::lock_owned(_): Send & Sync);
async_assert_fn!(tokio::sync::Mutex<Rc<u8>>::lock_owned(_): !Send & !Sync);
async_assert_fn!(tokio::sync::Notify::notified(_): Send & !Sync);
async_assert_fn!(tokio::sync::RwLock<u8>::read(_): Send & Sync);
async_assert_fn!(tokio::sync::RwLock<u8>::write(_): Send & Sync);
async_assert_fn!(tokio::sync::RwLock<Cell<u8>>::read(_): !Send & !Sync);
async_assert_fn!(tokio::sync::RwLock<Cell<u8>>::write(_): !Send & !Sync);
async_assert_fn!(tokio::sync::RwLock<Rc<u8>>::read(_): !Send & !Sync);
async_assert_fn!(tokio::sync::RwLock<Rc<u8>>::write(_): !Send & !Sync);
async_assert_fn!(tokio::sync::Semaphore::acquire(_): Send & Sync);
async_assert_fn!(tokio::sync::broadcast::Receiver<u8>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::broadcast::Receiver<Cell<u8>>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::broadcast::Receiver<Rc<u8>>::recv(_): !Send & !Sync);
async_assert_fn!(tokio::sync::mpsc::Receiver<u8>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::mpsc::Receiver<Cell<u8>>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::mpsc::Receiver<Rc<u8>>::recv(_): !Send & !Sync);
async_assert_fn!(tokio::sync::mpsc::Sender<u8>::send(_, u8): Send & Sync);
async_assert_fn!(tokio::sync::mpsc::Sender<Cell<u8>>::send(_, Cell<u8>): Send & !Sync);
async_assert_fn!(tokio::sync::mpsc::Sender<Rc<u8>>::send(_, Rc<u8>): !Send & !Sync);
async_assert_fn!(tokio::sync::mpsc::UnboundedReceiver<u8>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::mpsc::UnboundedReceiver<Cell<u8>>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::mpsc::UnboundedReceiver<Rc<u8>>::recv(_): !Send & !Sync);
async_assert_fn!(tokio::sync::watch::Receiver<u8>::recv(_): Send & Sync);
async_assert_fn!(tokio::sync::watch::Receiver<Cell<u8>>::recv(_): !Send & !Sync);
async_assert_fn!(tokio::sync::watch::Receiver<Rc<u8>>::recv(_): !Send & !Sync);
async_assert_fn!(tokio::sync::watch::Sender<u8>::closed(_): Send & Sync);
async_assert_fn!(tokio::sync::watch::Sender<Cell<u8>>::closed(_): !Send & !Sync);
async_assert_fn!(tokio::sync::watch::Sender<Rc<u8>>::closed(_): !Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<u32>::scope(_, u32, BoxFutureSync<()>): Send & Sync);
async_assert_fn!(tokio::task::LocalKey<u32>::scope(_, u32, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<u32>::scope(_, u32, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Cell<u32>>::scope(_, Cell<u32>, BoxFutureSync<()>): Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Cell<u32>>::scope(_, Cell<u32>, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Cell<u32>>::scope(_, Cell<u32>, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Rc<u32>>::scope(_, Rc<u32>, BoxFutureSync<()>): !Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Rc<u32>>::scope(_, Rc<u32>, BoxFutureSend<()>): !Send & !Sync);
async_assert_fn!(tokio::task::LocalKey<Rc<u32>>::scope(_, Rc<u32>, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::task::LocalSet::run_until(_, BoxFutureSync<()>): !Send & !Sync);
assert_value!(tokio::task::LocalSet: !Send & !Sync);
async_assert_fn!(tokio::time::advance(Duration): Send & Sync);
async_assert_fn!(tokio::time::delay_for(Duration): Send & Sync);
async_assert_fn!(tokio::time::delay_until(Instant): Send & Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFutureSync<()>): Send & Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::time::timeout(Duration, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::time::timeout_at(Instant, BoxFutureSync<()>): Send & Sync);
async_assert_fn!(tokio::time::timeout_at(Instant, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::time::timeout_at(Instant, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::time::Interval::tick(_): Send & Sync);
#[cfg(tokio_unstable)]
assert_value!(tokio::sync::CancellationToken: Send & Sync);
|