From 98915adce132a0e18fb999eb2e27f81cda633459 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Mon, 13 Feb 2023 16:34:22 +0100 Subject: [PATCH] Use consistent cfg attributes --- src/interest.rs | 6 +++--- src/sys/unix/net.rs | 10 +++++----- src/sys/unix/pipe.rs | 6 +++--- src/sys/unix/selector/kqueue.rs | 33 ++++++++++++++++----------------- src/sys/unix/selector/mod.rs | 8 ++++---- src/sys/unix/tcp.rs | 11 ++++------- src/sys/unix/uds/listener.rs | 9 +++------ tests/interest.rs | 2 +- tests/util/mod.rs | 4 ++-- tests/win_named_pipe.rs | 8 ++++---- 10 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/interest.rs b/src/interest.rs index 0aa0bda89..142478604 100644 --- a/src/interest.rs +++ b/src/interest.rs @@ -25,7 +25,7 @@ const WRITABLE: u8 = 0b0010; target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", )), allow(dead_code) )] @@ -45,7 +45,7 @@ impl Interest { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] pub const AIO: Interest = Interest(unsafe { NonZeroU8::new_unchecked(AIO) }); @@ -152,7 +152,7 @@ impl fmt::Debug for Interest { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] { if self.is_aio() { diff --git a/src/sys/unix/net.rs b/src/sys/unix/net.rs index 4454c7034..2396ab9eb 100644 --- a/src/sys/unix/net.rs +++ b/src/sys/unix/net.rs @@ -20,14 +20,14 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R target_os = "illumos", target_os = "linux", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] let socket_type = socket_type | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC; let socket = syscall!(socket(domain, socket_type, 0))?; // Mimick `libstd` and set `SO_NOSIGPIPE` on apple systems. - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] if let Err(err) = syscall!(setsockopt( socket, libc::SOL_SOCKET, @@ -40,7 +40,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R } // Darwin doesn't have SOCK_NONBLOCK or SOCK_CLOEXEC. - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] { if let Err(err) = syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK)) { let _ = syscall!(close(socket)); @@ -92,7 +92,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "ios", target_os = "macos", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] sin_len: 0, }; @@ -116,7 +116,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "ios", target_os = "macos", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] sin6_len: 0, #[cfg(target_os = "illumos")] diff --git a/src/sys/unix/pipe.rs b/src/sys/unix/pipe.rs index bb032a9cd..7b7e4db7c 100644 --- a/src/sys/unix/pipe.rs +++ b/src/sys/unix/pipe.rs @@ -188,12 +188,12 @@ pub fn new() -> io::Result<(Sender, Receiver)> { target_os = "android", target_os = "dragonfly", target_os = "freebsd", + target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", target_os = "openbsd", - target_os = "ios", - target_os = "macos", - target_os = "illumos", target_os = "redox", )))] compile_error!("unsupported target for `mio::unix::pipe`"); diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index c57e88e97..1eedec04f 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -21,7 +21,7 @@ type Count = libc::size_t; // Type of the `filter` field in the `kevent` structure. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] type Filter = libc::c_short; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "ios", target_os = "macos"))] type Filter = i16; #[cfg(target_os = "netbsd")] type Filter = u32; @@ -29,7 +29,7 @@ type Filter = u32; // Type of the `flags` field in the `kevent` structure. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] type Flags = libc::c_ushort; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "ios", target_os = "macos"))] type Flags = u16; #[cfg(target_os = "netbsd")] type Flags = u32; @@ -405,7 +405,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] { event.filter == libc::EVFILT_AIO @@ -414,7 +414,7 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", )))] { false @@ -450,7 +450,7 @@ pub mod event { target_os = "freebsd", target_os = "dragonfly", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::EVFILT_FS, #[cfg(target_os = "freebsd")] @@ -459,7 +459,7 @@ pub mod event { target_os = "freebsd", target_os = "dragonfly", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::EVFILT_USER, #[cfg(target_os = "freebsd")] @@ -516,49 +516,49 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_TRIGGER, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFNOP, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFAND, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFOR, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFCOPY, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFCTRLMASK, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] libc::NOTE_FFLAGSMASK, libc::NOTE_LOWAT, @@ -593,21 +593,21 @@ pub mod event { target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] libc::NOTE_TRACK, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] libc::NOTE_TRACKERR, #[cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] libc::NOTE_CHILD, #[cfg(any(target_os = "ios", target_os = "macos"))] @@ -635,7 +635,6 @@ pub mod event { #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] libc::NOTE_NSECONDS, #[cfg(any(target_os = "ios", target_os = "macos"))] - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] libc::NOTE_ABSOLUTE, #[cfg(any(target_os = "ios", target_os = "macos"))] libc::NOTE_LEEWAY, diff --git a/src/sys/unix/selector/mod.rs b/src/sys/unix/selector/mod.rs index 9ae4c1416..c06c7b18c 100644 --- a/src/sys/unix/selector/mod.rs +++ b/src/sys/unix/selector/mod.rs @@ -17,20 +17,20 @@ pub(crate) use self::epoll::{event, Event, Events, Selector}; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", target_os = "ios", target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" ))] mod kqueue; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd", target_os = "ios", target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" ))] pub(crate) use self::kqueue::{event, Event, Events, Selector}; diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 30790ef59..9513cc096 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -60,16 +60,13 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, #[cfg(any( // Android x86's seccomp profile forbids calls to `accept4(2)` // See https://github.com/tokio-rs/mio/issues/1445 for details - all( - not(target_arch="x86"), - target_os = "android" - ), + all(not(target_arch="x86"), target_os = "android"), target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", target_os = "linux", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", ))] let stream = { syscall!(accept4( @@ -85,10 +82,10 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, // OSes inherit the non-blocking flag from the listener, so we just have to // set `CLOEXEC`. #[cfg(any( - all(target_arch = "x86", target_os = "android"), target_os = "ios", target_os = "macos", - target_os = "redox" + target_os = "redox", + all(target_arch = "x86", target_os = "android"), ))] let stream = { syscall!(accept( diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index 838468260..3e33b3040 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -41,10 +41,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So target_os = "redox", // Android x86's seccomp profile forbids calls to `accept4(2)` // See https://github.com/tokio-rs/mio/issues/1445 for details - all( - target_arch = "x86", - target_os = "android" - ) + all(target_arch = "x86", target_os = "android"), )))] let socket = { let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC; @@ -58,10 +55,10 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So }; #[cfg(any( - target_os = "ios", - target_os = "macos", target_os = "netbsd", target_os = "redox", + target_os = "ios", + target_os = "macos", all(target_arch = "x86", target_os = "android") ))] let socket = syscall!(accept( diff --git a/tests/interest.rs b/tests/interest.rs index 1d77964ad..7814789f8 100644 --- a/tests/interest.rs +++ b/tests/interest.rs @@ -29,7 +29,7 @@ fn fmt_debug() { target_os = "dragonfly", target_os = "freebsd", target_os = "ios", - target_os = "macos" + target_os = "macos", ))] { assert_eq!(format!("{:?}", Interest::AIO), "AIO"); diff --git a/tests/util/mod.rs b/tests/util/mod.rs index db667c04d..b1e04e22d 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -249,9 +249,9 @@ pub fn set_linger_zero(socket: &TcpStream) { libc::setsockopt( socket.as_raw_fd(), libc::SOL_SOCKET, - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] libc::SO_LINGER_SEC, - #[cfg(not(target_vendor = "apple"))] + #[cfg(not(any(target_os = "ios", target_os = "macos")))] libc::SO_LINGER, &val as *const libc::linger as *const libc::c_void, size_of::() as libc::socklen_t, diff --git a/tests/win_named_pipe.rs b/tests/win_named_pipe.rs index 50f281317..e79d2fba4 100644 --- a/tests/win_named_pipe.rs +++ b/tests/win_named_pipe.rs @@ -260,7 +260,7 @@ fn connect_twice() { )); t!(poll .registry() - .register(&mut c1, Token(1), Interest::READABLE | Interest::WRITABLE,)); + .register(&mut c1, Token(1), Interest::READABLE | Interest::WRITABLE)); drop(c1); let mut events = Events::with_capacity(128); @@ -290,7 +290,7 @@ fn connect_twice() { let mut c2 = client(&name); t!(poll .registry() - .register(&mut c2, Token(2), Interest::READABLE | Interest::WRITABLE,)); + .register(&mut c2, Token(2), Interest::READABLE | Interest::WRITABLE)); 'outer: loop { t!(poll.poll(&mut events, None)); @@ -311,7 +311,7 @@ fn reregister_deregister_before_register() { assert_eq!( poll.registry() - .reregister(&mut pipe, Token(0), Interest::READABLE,) + .reregister(&mut pipe, Token(0), Interest::READABLE) .unwrap_err() .kind(), io::ErrorKind::NotFound, @@ -337,7 +337,7 @@ fn reregister_deregister_different_poll() { assert_eq!( poll2 .registry() - .reregister(&mut pipe, Token(0), Interest::READABLE,) + .reregister(&mut pipe, Token(0), Interest::READABLE) .unwrap_err() .kind(), io::ErrorKind::AlreadyExists,