From ba9fa9fbcbb8d18dc10eccba361d5ca7a79844cf Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 23 Dec 2023 17:55:41 +0100 Subject: [PATCH] Cleanup import statements Mio once started with the order of std, external crates, than crate internal imports. At some points this order was not enforce properly and we ended up with a mix imports statements. This commit orders everything following imports from std, external crates, then crate internal (the `group_imports="StdExternalCrate"` rustfmt option). This has no functional change. --- examples/tcp_listenfd_server.rs | 7 ++++--- examples/tcp_server.rs | 7 ++++--- examples/udp_server.rs | 3 ++- src/event/event.rs | 4 ++-- src/event/events.rs | 4 ++-- src/event/mod.rs | 6 +++--- src/event/source.rs | 4 ++-- src/net/mod.rs | 6 +++--- src/net/tcp/mod.rs | 4 ++-- src/net/uds/mod.rs | 7 +++---- src/sys/mod.rs | 12 ++++++------ src/sys/shell/mod.rs | 4 ++-- src/sys/shell/selector.rs | 3 ++- src/sys/shell/uds.rs | 9 ++++++--- src/sys/shell/waker.rs | 3 ++- src/sys/unix/mod.rs | 17 +++++++++-------- src/sys/unix/selector/kqueue.rs | 6 +++--- src/sys/unix/selector/mod.rs | 8 ++++---- src/sys/unix/selector/poll.rs | 11 ++++++----- src/sys/unix/sourcefd.rs | 4 ++-- src/sys/unix/udp.rs | 7 +++---- src/sys/unix/uds/datagram.rs | 6 +++--- src/sys/unix/uds/listener.rs | 7 ++++--- src/sys/unix/uds/mod.rs | 5 +++-- src/sys/unix/uds/socketaddr.rs | 3 ++- src/sys/unix/uds/stream.rs | 6 +++--- src/sys/unix/waker.rs | 25 ++++++++++++++----------- src/sys/windows/afd.rs | 5 ++--- src/sys/windows/event.rs | 4 ++-- src/sys/windows/handle.rs | 1 + src/sys/windows/iocp.rs | 10 ++++------ src/sys/windows/named_pipe.rs | 3 +-- src/sys/windows/net.rs | 3 +-- src/sys/windows/overlapped.rs | 4 ++-- src/sys/windows/selector.rs | 32 ++++++++++++++------------------ src/sys/windows/tcp.rs | 1 + src/sys/windows/udp.rs | 3 ++- src/sys/windows/waker.rs | 9 ++++----- src/waker.rs | 4 ++-- tests/aio.rs | 15 +++++++-------- tests/close_on_drop.rs | 2 +- tests/poll.rs | 9 ++++----- tests/tcp.rs | 6 +++--- tests/tcp_listener.rs | 5 +++-- tests/tcp_stream.rs | 3 ++- tests/udp_socket.rs | 11 +++++------ tests/unix_datagram.rs | 5 +++-- tests/unix_listener.rs | 5 +++-- tests/unix_stream.rs | 5 +++-- tests/util/mod.rs | 1 + tests/waker.rs | 3 ++- tests/win_named_pipe.rs | 3 ++- 52 files changed, 176 insertions(+), 164 deletions(-) diff --git a/examples/tcp_listenfd_server.rs b/examples/tcp_listenfd_server.rs index a0f1c42fa..be770ad5f 100644 --- a/examples/tcp_listenfd_server.rs +++ b/examples/tcp_listenfd_server.rs @@ -4,13 +4,14 @@ // cargo +nightly build --target wasm32-wasi --example tcp_listenfd_server --features="os-poll net" // wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_listenfd_server.wasm -use mio::event::Event; -use mio::net::{TcpListener, TcpStream}; -use mio::{Events, Interest, Poll, Registry, Token}; use std::collections::HashMap; use std::io::{self, Read, Write}; use std::str::from_utf8; +use mio::event::Event; +use mio::net::{TcpListener, TcpStream}; +use mio::{Events, Interest, Poll, Registry, Token}; + // Setup some tokens to allow us to identify which event is for which socket. const SERVER: Token = Token(0); diff --git a/examples/tcp_server.rs b/examples/tcp_server.rs index 21e2f2a82..1d58657a8 100644 --- a/examples/tcp_server.rs +++ b/examples/tcp_server.rs @@ -1,12 +1,13 @@ // You can run this example from the root of the mio repo: // cargo run --example tcp_server --features="os-poll net" -use mio::event::Event; -use mio::net::{TcpListener, TcpStream}; -use mio::{Events, Interest, Poll, Registry, Token}; use std::collections::HashMap; use std::io::{self, Read, Write}; use std::str::from_utf8; +use mio::event::Event; +use mio::net::{TcpListener, TcpStream}; +use mio::{Events, Interest, Poll, Registry, Token}; + // Setup some tokens to allow us to identify which event is for which socket. const SERVER: Token = Token(0); diff --git a/examples/udp_server.rs b/examples/udp_server.rs index 698d710cd..5e5632075 100644 --- a/examples/udp_server.rs +++ b/examples/udp_server.rs @@ -1,8 +1,9 @@ // You can run this example from the root of the mio repo: // cargo run --example udp_server --features="os-poll net" +use std::io; + use log::warn; use mio::{Events, Interest, Poll, Token}; -use std::io; // A token to allow us to identify which event is for the `UdpSocket`. const UDP_SOCKET: Token = Token(0); diff --git a/src/event/event.rs b/src/event/event.rs index 2d85742b9..4a3bdf6dc 100644 --- a/src/event/event.rs +++ b/src/event/event.rs @@ -1,7 +1,7 @@ -use crate::{sys, Token}; - use std::fmt; +use crate::{sys, Token}; + /// A readiness event. /// /// `Event` is a readiness state paired with a [`Token`]. It is returned by diff --git a/src/event/events.rs b/src/event/events.rs index f3c5a2f02..19b63aa91 100644 --- a/src/event/events.rs +++ b/src/event/events.rs @@ -1,8 +1,8 @@ +use std::fmt; + use crate::event::Event; use crate::sys; -use std::fmt; - /// A collection of readiness events. /// /// `Events` is passed as an argument to [`Poll::poll`] and will be used to diff --git a/src/event/mod.rs b/src/event/mod.rs index 8e17f82ee..78e83ba36 100644 --- a/src/event/mod.rs +++ b/src/event/mod.rs @@ -5,6 +5,6 @@ mod event; mod events; mod source; -pub use self::event::Event; -pub use self::events::{Events, Iter}; -pub use self::source::Source; +pub use event::Event; +pub use events::{Events, Iter}; +pub use source::Source; diff --git a/src/event/source.rs b/src/event/source.rs index 619f72d42..22f6ff93b 100644 --- a/src/event/source.rs +++ b/src/event/source.rs @@ -1,7 +1,7 @@ -use crate::{Interest, Registry, Token}; - use std::io; +use crate::{Interest, Registry, Token}; + /// An event source that may be registered with [`Registry`]. /// /// Types that implement `event::Source` can be registered with diff --git a/src/net/mod.rs b/src/net/mod.rs index 7d714ca00..4502e2b85 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -26,14 +26,14 @@ //! give is to always call receive with a large enough buffer. mod tcp; -pub use self::tcp::{TcpListener, TcpStream}; +pub use tcp::{TcpListener, TcpStream}; #[cfg(not(target_os = "wasi"))] mod udp; #[cfg(not(target_os = "wasi"))] -pub use self::udp::UdpSocket; +pub use udp::UdpSocket; #[cfg(unix)] mod uds; #[cfg(unix)] -pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream}; +pub use uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream}; diff --git a/src/net/tcp/mod.rs b/src/net/tcp/mod.rs index 94af5c10e..5374b1d14 100644 --- a/src/net/tcp/mod.rs +++ b/src/net/tcp/mod.rs @@ -1,5 +1,5 @@ mod listener; -pub use self::listener::TcpListener; +pub use listener::TcpListener; mod stream; -pub use self::stream::TcpStream; +pub use stream::TcpStream; diff --git a/src/net/uds/mod.rs b/src/net/uds/mod.rs index 6b4ffdc43..b4cd4dfd8 100644 --- a/src/net/uds/mod.rs +++ b/src/net/uds/mod.rs @@ -1,10 +1,9 @@ mod datagram; -pub use self::datagram::UnixDatagram; +pub use datagram::UnixDatagram; mod listener; -pub use self::listener::UnixListener; +pub use listener::UnixListener; mod stream; -pub use self::stream::UnixStream; - pub use crate::sys::SocketAddr; +pub use stream::UnixStream; diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 04e0b2000..b79bb602f 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -55,34 +55,34 @@ cfg_os_poll! { cfg_os_poll! { mod unix; #[allow(unused_imports)] - pub use self::unix::*; + pub use unix::*; } #[cfg(windows)] cfg_os_poll! { mod windows; - pub use self::windows::*; + pub use windows::*; } #[cfg(target_os = "wasi")] cfg_os_poll! { mod wasi; - pub(crate) use self::wasi::*; + pub(crate) use wasi::*; } cfg_not_os_poll! { mod shell; - pub(crate) use self::shell::*; + pub(crate) use shell::*; #[cfg(unix)] cfg_any_os_ext! { mod unix; #[cfg(feature = "os-ext")] - pub use self::unix::SourceFd; + pub use unix::SourceFd; } #[cfg(unix)] cfg_net! { - pub use self::unix::SocketAddr; + pub use unix::SocketAddr; } } diff --git a/src/sys/shell/mod.rs b/src/sys/shell/mod.rs index 20ab7df8e..ed89a3e59 100644 --- a/src/sys/shell/mod.rs +++ b/src/sys/shell/mod.rs @@ -5,12 +5,12 @@ macro_rules! os_required { } mod selector; -pub(crate) use self::selector::{event, Event, Events, Selector}; +pub(crate) use selector::{event, Event, Events, Selector}; #[cfg(not(target_os = "wasi"))] mod waker; #[cfg(not(target_os = "wasi"))] -pub(crate) use self::waker::Waker; +pub(crate) use waker::Waker; cfg_net! { pub(crate) mod tcp; diff --git a/src/sys/shell/selector.rs b/src/sys/shell/selector.rs index 83456ef87..13488297b 100644 --- a/src/sys/shell/selector.rs +++ b/src/sys/shell/selector.rs @@ -76,9 +76,10 @@ impl AsRawFd for Selector { #[allow(clippy::trivially_copy_pass_by_ref)] pub mod event { + use std::fmt; + use crate::sys::Event; use crate::Token; - use std::fmt; pub fn token(_: &Event) -> Token { os_required!(); diff --git a/src/sys/shell/uds.rs b/src/sys/shell/uds.rs index bac547b03..4129e77c7 100644 --- a/src/sys/shell/uds.rs +++ b/src/sys/shell/uds.rs @@ -1,9 +1,10 @@ pub(crate) mod datagram { - use crate::net::SocketAddr; use std::io; use std::os::unix::net; use std::path::Path; + use crate::net::SocketAddr; + pub(crate) fn bind(_: &Path) -> io::Result { os_required!() } @@ -33,11 +34,12 @@ pub(crate) mod datagram { } pub(crate) mod listener { - use crate::net::{SocketAddr, UnixStream}; use std::io; use std::os::unix::net; use std::path::Path; + use crate::net::{SocketAddr, UnixStream}; + pub(crate) fn bind(_: &Path) -> io::Result { os_required!() } @@ -56,11 +58,12 @@ pub(crate) mod listener { } pub(crate) mod stream { - use crate::net::SocketAddr; use std::io; use std::os::unix::net; use std::path::Path; + use crate::net::SocketAddr; + pub(crate) fn connect(_: &Path) -> io::Result { os_required!() } diff --git a/src/sys/shell/waker.rs b/src/sys/shell/waker.rs index bbdd7c33a..1e5408aea 100644 --- a/src/sys/shell/waker.rs +++ b/src/sys/shell/waker.rs @@ -1,6 +1,7 @@ +use std::io; + use crate::sys::Selector; use crate::Token; -use std::io; #[derive(Debug)] pub struct Waker {} diff --git a/src/sys/unix/mod.rs b/src/sys/unix/mod.rs index d512aeaa1..8a85f87d2 100644 --- a/src/sys/unix/mod.rs +++ b/src/sys/unix/mod.rs @@ -16,14 +16,14 @@ macro_rules! syscall { cfg_os_poll! { mod selector; - pub(crate) use self::selector::{event, Event, Events, Selector}; + pub(crate) use selector::{event, Event, Events, Selector}; mod sourcefd; #[cfg(feature = "os-ext")] - pub use self::sourcefd::SourceFd; + pub use sourcefd::SourceFd; mod waker; - pub(crate) use self::waker::Waker; + pub(crate) use waker::Waker; cfg_net! { mod net; @@ -31,7 +31,7 @@ cfg_os_poll! { pub(crate) mod tcp; pub(crate) mod udp; pub(crate) mod uds; - pub use self::uds::SocketAddr; + pub use uds::SocketAddr; } cfg_io_source! { @@ -40,6 +40,7 @@ cfg_os_poll! { mod stateless_io_source { use std::io; use std::os::fd::RawFd; + use crate::Registry; use crate::Token; use crate::Interest; @@ -90,10 +91,10 @@ cfg_os_poll! { } #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "solaris",target_os = "vita")))] - pub(crate) use self::stateless_io_source::IoSourceState; + pub(crate) use stateless_io_source::IoSourceState; #[cfg(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita"))] - pub(crate) use self::selector::IoSourceState; + pub(crate) use selector::IoSourceState; } #[cfg(any( @@ -116,12 +117,12 @@ cfg_os_poll! { cfg_not_os_poll! { cfg_net! { mod uds; - pub use self::uds::SocketAddr; + pub use uds::SocketAddr; } cfg_any_os_ext! { mod sourcefd; #[cfg(feature = "os-ext")] - pub use self::sourcefd::SourceFd; + pub use sourcefd::SourceFd; } } diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index c6a563d66..175bd0fea 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -1,4 +1,3 @@ -use crate::{Interest, Token}; use std::mem::{self, MaybeUninit}; use std::ops::{Deref, DerefMut}; use std::os::fd::{AsRawFd, FromRawFd, OwnedFd, RawFd}; @@ -7,6 +6,8 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use std::{cmp, io, ptr, slice}; +use crate::{Interest, Token}; + /// Unique id for use as `SelectorId`. #[cfg(debug_assertions)] static NEXT_ID: AtomicUsize = AtomicUsize::new(1); @@ -353,11 +354,10 @@ unsafe impl Sync for Events {} pub mod event { use std::fmt; + use super::{Filter, Flags}; use crate::sys::Event; use crate::Token; - use super::{Filter, Flags}; - pub fn token(event: &Event) -> Token { Token(event.udata as usize) } diff --git a/src/sys/unix/selector/mod.rs b/src/sys/unix/selector/mod.rs index e148556f8..954209762 100644 --- a/src/sys/unix/selector/mod.rs +++ b/src/sys/unix/selector/mod.rs @@ -18,7 +18,7 @@ mod epoll; target_os = "redox", ) ))] -pub(crate) use self::epoll::{event, Event, Events, Selector}; +pub(crate) use epoll::{event, Event, Events, Selector}; #[cfg(any( mio_unsupported_force_poll_poll, @@ -32,11 +32,11 @@ mod poll; target_os = "solaris", target_os = "vita" ))] -pub(crate) use self::poll::{event, Event, Events, Selector}; +pub(crate) use poll::{event, Event, Events, Selector}; cfg_io_source! { #[cfg(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita"))] - pub(crate) use self::poll::IoSourceState; + pub(crate) use poll::IoSourceState; } #[cfg(all( @@ -67,4 +67,4 @@ mod kqueue; target_os = "watchos", ), ))] -pub(crate) use self::kqueue::{event, Event, Events, Selector}; +pub(crate) use kqueue::{event, Event, Events, Selector}; diff --git a/src/sys/unix/selector/poll.rs b/src/sys/unix/selector/poll.rs index ea8e998ac..bdedeea11 100644 --- a/src/sys/unix/selector/poll.rs +++ b/src/sys/unix/selector/poll.rs @@ -3,17 +3,17 @@ // Permission to use this code has been granted by original author: // https://github.com/tokio-rs/mio/pull/1602#issuecomment-1218441031 -use crate::sys::unix::waker::WakerInternal; -use crate::{Interest, Token}; use std::collections::HashMap; use std::fmt::{Debug, Formatter}; use std::os::fd::{AsRawFd, RawFd}; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Arc, Condvar, Mutex}; use std::time::Duration; use std::{cmp, fmt, io}; +use crate::sys::unix::waker::WakerInternal; +use crate::{Interest, Token}; + /// Unique id for use as `SelectorId`. #[cfg(debug_assertions)] static NEXT_ID: AtomicUsize = AtomicUsize::new(1); @@ -540,10 +540,11 @@ pub struct Event { pub type Events = Vec; pub mod event { + use std::fmt; + use crate::sys::unix::selector::poll::POLLRDHUP; use crate::sys::Event; use crate::Token; - use std::fmt; pub fn token(event: &Event) -> Token { event.token diff --git a/src/sys/unix/sourcefd.rs b/src/sys/unix/sourcefd.rs index f4c5c7f1f..313b97f34 100644 --- a/src/sys/unix/sourcefd.rs +++ b/src/sys/unix/sourcefd.rs @@ -1,8 +1,8 @@ -use crate::{event, Interest, Registry, Token}; - use std::io; use std::os::fd::RawFd; +use crate::{event, Interest, Registry, Token}; + /// Adapter for [`RawFd`] providing an [`event::Source`] implementation. /// /// `SourceFd` enables registering any type with an FD with [`Poll`]. diff --git a/src/sys/unix/udp.rs b/src/sys/unix/udp.rs index 303d6226b..79841c4dc 100644 --- a/src/sys/unix/udp.rs +++ b/src/sys/unix/udp.rs @@ -1,9 +1,8 @@ -use crate::sys::unix::net::{new_ip_socket, socket_addr}; - -use std::io; -use std::mem; use std::net::{self, SocketAddr}; use std::os::fd::{AsRawFd, FromRawFd}; +use std::{io, mem}; + +use crate::sys::unix::net::{new_ip_socket, socket_addr}; pub fn bind(addr: SocketAddr) -> io::Result { let fd = new_ip_socket(addr, libc::SOCK_DGRAM)?; diff --git a/src/sys/unix/uds/datagram.rs b/src/sys/unix/uds/datagram.rs index 4418a3f4a..f68caf3c0 100644 --- a/src/sys/unix/uds/datagram.rs +++ b/src/sys/unix/uds/datagram.rs @@ -1,12 +1,12 @@ -use super::{socket_addr, SocketAddr}; -use crate::sys::unix::net::new_socket; - use std::io; use std::os::fd::{AsRawFd, FromRawFd}; use std::os::unix::ffi::OsStrExt; use std::os::unix::net; use std::path::Path; +use crate::sys::unix::net::new_socket; +use crate::sys::unix::uds::{socket_addr, SocketAddr}; + pub(crate) fn bind(path: &Path) -> io::Result { let (sockaddr, socklen) = socket_addr(path.as_os_str().as_bytes())?; let sockaddr = &sockaddr as *const libc::sockaddr_un as *const _; diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index 9d52eb61c..5c221db40 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -1,12 +1,13 @@ -use super::socket_addr; -use crate::net::{SocketAddr, UnixStream}; -use crate::sys::unix::net::new_socket; use std::os::fd::{AsRawFd, FromRawFd}; use std::os::unix::ffi::OsStrExt; use std::os::unix::net; use std::path::Path; use std::{io, mem}; +use crate::net::{SocketAddr, UnixStream}; +use crate::sys::unix::net::new_socket; +use crate::sys::unix::uds::socket_addr; + pub(crate) fn bind(path: &Path) -> io::Result { let socket_address = { let (sockaddr, socklen) = socket_addr(path.as_os_str().as_bytes())?; diff --git a/src/sys/unix/uds/mod.rs b/src/sys/unix/uds/mod.rs index 72b8b755a..6700a30c5 100644 --- a/src/sys/unix/uds/mod.rs +++ b/src/sys/unix/uds/mod.rs @@ -1,5 +1,5 @@ mod socketaddr; -pub use self::socketaddr::SocketAddr; +pub use socketaddr::SocketAddr; /// Get the `sun_path` field offset of `sockaddr_un` for the target OS. /// @@ -129,11 +129,12 @@ cfg_os_poll! { #[cfg(test)] mod tests { - use super::{path_offset, socket_addr}; use std::os::unix::ffi::OsStrExt; use std::path::Path; use std::str; + use super::{path_offset, socket_addr}; + #[test] fn pathname_address() { const PATH: &str = "./foo/bar.txt"; diff --git a/src/sys/unix/uds/socketaddr.rs b/src/sys/unix/uds/socketaddr.rs index 8e0ef53a4..4d562d022 100644 --- a/src/sys/unix/uds/socketaddr.rs +++ b/src/sys/unix/uds/socketaddr.rs @@ -1,9 +1,10 @@ -use super::path_offset; use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; use std::path::Path; use std::{ascii, fmt}; +use crate::sys::uds::path_offset; + /// An address associated with a `mio` specific Unix socket. /// /// This is implemented instead of imported from [`net::SocketAddr`] because diff --git a/src/sys/unix/uds/stream.rs b/src/sys/unix/uds/stream.rs index 50000dec4..d2081691c 100644 --- a/src/sys/unix/uds/stream.rs +++ b/src/sys/unix/uds/stream.rs @@ -1,12 +1,12 @@ -use super::{socket_addr, SocketAddr}; -use crate::sys::unix::net::new_socket; - use std::io; use std::os::fd::{AsRawFd, FromRawFd}; use std::os::unix::ffi::OsStrExt; use std::os::unix::net; use std::path::Path; +use crate::sys::unix::net::new_socket; +use crate::sys::unix::uds::{socket_addr, SocketAddr}; + pub(crate) fn connect(path: &Path) -> io::Result { let socket_address = { let (sockaddr, socklen) = socket_addr(path.as_os_str().as_bytes())?; diff --git a/src/sys/unix/waker.rs b/src/sys/unix/waker.rs index c9c246fe8..43effaf79 100644 --- a/src/sys/unix/waker.rs +++ b/src/sys/unix/waker.rs @@ -13,6 +13,9 @@ not(any(target_os = "solaris", target_os = "vita")), ))] mod fdbased { + use std::io; + use std::os::fd::AsRawFd; + #[cfg(all( not(mio_unsupported_force_waker_pipe), any(target_os = "linux", target_os = "android"), @@ -30,8 +33,6 @@ mod fdbased { use crate::sys::unix::waker::pipe::WakerInternal; use crate::sys::Selector; use crate::{Interest, Token}; - use std::io; - use std::os::fd::AsRawFd; #[derive(Debug)] pub struct Waker { @@ -65,7 +66,7 @@ mod fdbased { )), not(any(target_os = "solaris", target_os = "vita")), ))] -pub use self::fdbased::Waker; +pub use fdbased::Waker; #[cfg(all( not(mio_unsupported_force_waker_pipe), @@ -144,7 +145,7 @@ mod eventfd { not(mio_unsupported_force_waker_pipe), any(target_os = "linux", target_os = "android", target_os = "espidf") ))] -pub(crate) use self::eventfd::WakerInternal; +pub(crate) use eventfd::WakerInternal; #[cfg(all( not(mio_unsupported_force_waker_pipe), @@ -157,11 +158,11 @@ pub(crate) use self::eventfd::WakerInternal; ) ))] mod kqueue { + use std::io; + use crate::sys::Selector; use crate::Token; - use std::io; - /// Waker backed by kqueue user space notifications (`EVFILT_USER`). /// /// The implementation is fairly simple, first the kqueue must be setup to @@ -197,7 +198,7 @@ mod kqueue { target_os = "watchos", ) ))] -pub use self::kqueue::Waker; +pub use kqueue::Waker; #[cfg(any( mio_unsupported_force_waker_pipe, @@ -211,11 +212,12 @@ pub use self::kqueue::Waker; target_os = "vita", ))] mod pipe { - use crate::sys::unix::pipe; use std::fs::File; use std::io::{self, Read, Write}; use std::os::fd::{AsRawFd, FromRawFd, RawFd}; + use crate::sys::unix::pipe; + /// Waker backed by a unix pipe. /// /// Waker controls both the sending and receiving ends and empties the pipe @@ -299,7 +301,7 @@ mod pipe { target_os = "solaris", target_os = "vita", ))] -pub(crate) use self::pipe::WakerInternal; +pub(crate) use pipe::WakerInternal; #[cfg(any( mio_unsupported_force_poll_poll, @@ -307,9 +309,10 @@ pub(crate) use self::pipe::WakerInternal; target_os = "vita" ))] mod poll { + use std::io; + use crate::sys::Selector; use crate::Token; - use std::io; #[derive(Debug)] pub struct Waker { @@ -336,4 +339,4 @@ mod poll { target_os = "solaris", target_os = "vita" ))] -pub use self::poll::Waker; +pub use poll::Waker; diff --git a/src/sys/windows/afd.rs b/src/sys/windows/afd.rs index 11373cfca..a5c570026 100644 --- a/src/sys/windows/afd.rs +++ b/src/sys/windows/afd.rs @@ -1,9 +1,8 @@ use std::ffi::c_void; -use std::fmt; use std::fs::File; -use std::io; use std::mem::size_of; use std::os::windows::io::AsRawHandle; +use std::{fmt, io}; use windows_sys::Wdk::Storage::FileSystem::NtCancelIoFileEx; use windows_sys::Wdk::System::IO::NtDeviceIoControlFile; @@ -127,7 +126,7 @@ cfg_io_source! { }; use windows_sys::Win32::System::WindowsProgramming::FILE_SKIP_SET_EVENT_ON_HANDLE; - use super::iocp::CompletionPort; + use crate::sys::windows::iocp::CompletionPort; const AFD_HELPER_ATTRIBUTES: OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES { Length: size_of::() as u32, diff --git a/src/sys/windows/event.rs b/src/sys/windows/event.rs index 731bd6067..5a48e8d42 100644 --- a/src/sys/windows/event.rs +++ b/src/sys/windows/event.rs @@ -1,7 +1,7 @@ use std::fmt; -use super::afd; -use super::iocp::CompletionStatus; +use crate::sys::windows::afd; +use crate::sys::windows::iocp::CompletionStatus; use crate::Token; #[derive(Clone)] diff --git a/src/sys/windows/handle.rs b/src/sys/windows/handle.rs index 5b9ac0b62..a17151f6a 100644 --- a/src/sys/windows/handle.rs +++ b/src/sys/windows/handle.rs @@ -1,4 +1,5 @@ use std::os::windows::io::RawHandle; + use windows_sys::Win32::Foundation::{CloseHandle, HANDLE}; /// Wrapper around a Windows HANDLE so that we close it upon drop in all scenarios diff --git a/src/sys/windows/iocp.rs b/src/sys/windows/iocp.rs index c71b695d4..12459b787 100644 --- a/src/sys/windows/iocp.rs +++ b/src/sys/windows/iocp.rs @@ -1,12 +1,8 @@ //! Bindings to IOCP, I/O Completion Ports -use super::{Handle, Overlapped}; -use std::cmp; -use std::fmt; -use std::io; -use std::mem; -use std::os::windows::io::*; +use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle}; use std::time::Duration; +use std::{cmp, fmt, io, mem}; use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE}; use windows_sys::Win32::System::IO::{ @@ -14,6 +10,8 @@ use windows_sys::Win32::System::IO::{ OVERLAPPED_ENTRY, }; +use crate::sys::windows::{Handle, Overlapped}; + /// A handle to an Windows I/O Completion Port. #[derive(Debug)] pub(crate) struct CompletionPort { diff --git a/src/sys/windows/named_pipe.rs b/src/sys/windows/named_pipe.rs index 23f85d1eb..2bc36fccf 100644 --- a/src/sys/windows/named_pipe.rs +++ b/src/sys/windows/named_pipe.rs @@ -24,8 +24,7 @@ use windows_sys::Win32::System::IO::{ use crate::event::Source; use crate::sys::windows::iocp::{CompletionPort, CompletionStatus}; use crate::sys::windows::{Event, Handle, Overlapped}; -use crate::Registry; -use crate::{Interest, Token}; +use crate::{Interest, Registry, Token}; /// Non-blocking windows named pipe. /// diff --git a/src/sys/windows/net.rs b/src/sys/windows/net.rs index 5cc235335..8bd637dcb 100644 --- a/src/sys/windows/net.rs +++ b/src/sys/windows/net.rs @@ -1,7 +1,6 @@ -use std::io; -use std::mem; use std::net::SocketAddr; use std::sync::Once; +use std::{io, mem}; use windows_sys::Win32::Networking::WinSock::{ closesocket, ioctlsocket, socket, AF_INET, AF_INET6, FIONBIO, IN6_ADDR, IN6_ADDR_0, diff --git a/src/sys/windows/overlapped.rs b/src/sys/windows/overlapped.rs index d1456ded4..cd867bb12 100644 --- a/src/sys/windows/overlapped.rs +++ b/src/sys/windows/overlapped.rs @@ -1,10 +1,10 @@ -use crate::sys::windows::Event; - use std::cell::UnsafeCell; use std::fmt; use windows_sys::Win32::System::IO::{OVERLAPPED, OVERLAPPED_ENTRY}; +use crate::sys::windows::Event; + #[repr(C)] pub(crate) struct Overlapped { inner: UnsafeCell, diff --git a/src/sys/windows/selector.rs b/src/sys/windows/selector.rs index 23d7bc5c1..eb58d6449 100644 --- a/src/sys/windows/selector.rs +++ b/src/sys/windows/selector.rs @@ -1,16 +1,3 @@ -use super::afd::{self, Afd, AfdPollInfo}; -use super::io_status_block::IoStatusBlock; -use super::Event; -use crate::sys::Events; - -cfg_net! { - use crate::sys::event::{ - ERROR_FLAGS, READABLE_FLAGS, READ_CLOSED_FLAGS, WRITABLE_FLAGS, WRITE_CLOSED_FLAGS, - }; - use crate::Interest; -} - -use super::iocp::{CompletionPort, CompletionStatus}; use std::collections::VecDeque; use std::ffi::c_void; use std::io; @@ -28,6 +15,11 @@ use windows_sys::Win32::Foundation::{ }; use windows_sys::Win32::System::IO::OVERLAPPED; +use crate::sys::windows::afd::{self, Afd, AfdPollInfo}; +use crate::sys::windows::io_status_block::IoStatusBlock; +use crate::sys::windows::iocp::{CompletionPort, CompletionStatus}; +use crate::sys::windows::{Event, Events}; + #[derive(Debug)] struct AfdGroup { #[cfg_attr(not(feature = "net"), allow(dead_code))] @@ -370,7 +362,7 @@ impl Selector { } cfg_io_source! { - use super::InternalState; + use super::{InternalState, Overlapped}; use crate::Token; impl Selector { @@ -497,7 +489,7 @@ impl SelectorInner { continue; } else if iocp_event.token() % 2 == 1 { // Handle is a named pipe. This could be extended to be any non-AFD event. - let callback = (*(iocp_event.overlapped() as *mut super::Overlapped)).callback; + let callback = (*(iocp_event.overlapped() as *mut Overlapped)).callback; let len = events.len(); callback(iocp_event.entry(), Some(events)); @@ -697,9 +689,8 @@ impl Drop for SelectorInner { // Custom event } else if iocp_event.token() % 2 == 1 { // Named pipe, dispatch the event so it can release resources - let callback = unsafe { - (*(iocp_event.overlapped() as *mut super::Overlapped)).callback - }; + let callback = + unsafe { (*(iocp_event.overlapped() as *mut Overlapped)).callback }; callback(iocp_event.entry(), None); } else { @@ -725,6 +716,11 @@ impl Drop for SelectorInner { } cfg_net! { + use crate::sys::event::{ + ERROR_FLAGS, READABLE_FLAGS, READ_CLOSED_FLAGS, WRITABLE_FLAGS, WRITE_CLOSED_FLAGS, + }; + use crate::Interest; + fn interests_to_afd_flags(interests: Interest) -> u32 { let mut flags = 0; diff --git a/src/sys/windows/tcp.rs b/src/sys/windows/tcp.rs index addd1e8d8..a06eb5a23 100644 --- a/src/sys/windows/tcp.rs +++ b/src/sys/windows/tcp.rs @@ -48,6 +48,7 @@ pub(crate) fn connect(socket: &net::TcpStream, addr: SocketAddr) -> io::Result<( pub(crate) fn listen(socket: &net::TcpListener, backlog: u32) -> io::Result<()> { use std::convert::TryInto; + use WinSock::listen; let backlog = backlog.try_into().unwrap_or(i32::max_value()); diff --git a/src/sys/windows/udp.rs b/src/sys/windows/udp.rs index 87e269fa3..1179a4950 100644 --- a/src/sys/windows/udp.rs +++ b/src/sys/windows/udp.rs @@ -4,11 +4,12 @@ use std::net::{self, SocketAddr}; use std::os::windows::io::{AsRawSocket, FromRawSocket}; use std::os::windows::raw::SOCKET as StdSocket; // windows-sys uses usize, stdlib uses u32/u64. -use crate::sys::windows::net::{new_ip_socket, socket_addr}; use windows_sys::Win32::Networking::WinSock::{ bind as win_bind, getsockopt, IPPROTO_IPV6, IPV6_V6ONLY, SOCKET_ERROR, SOCK_DGRAM, }; +use crate::sys::windows::net::{new_ip_socket, socket_addr}; + pub fn bind(addr: SocketAddr) -> io::Result { let raw_socket = new_ip_socket(addr, SOCK_DGRAM)?; let socket = unsafe { net::UdpSocket::from_raw_socket(raw_socket as StdSocket) }; diff --git a/src/sys/windows/waker.rs b/src/sys/windows/waker.rs index 103aa01a7..eab011c2f 100644 --- a/src/sys/windows/waker.rs +++ b/src/sys/windows/waker.rs @@ -1,11 +1,10 @@ -use crate::sys::windows::Event; -use crate::sys::windows::Selector; -use crate::Token; - -use super::iocp::CompletionPort; use std::io; use std::sync::Arc; +use crate::sys::windows::iocp::CompletionPort; +use crate::sys::windows::{Event, Selector}; +use crate::Token; + #[derive(Debug)] pub struct Waker { token: Token, diff --git a/src/waker.rs b/src/waker.rs index 92fdb4c16..9a920c6c3 100644 --- a/src/waker.rs +++ b/src/waker.rs @@ -1,7 +1,7 @@ -use crate::{sys, Registry, Token}; - use std::io; +use crate::{sys, Registry, Token}; + /// Waker allows cross-thread waking of [`Poll`]. /// /// When created it will cause events with [`readable`] readiness and the diff --git a/tests/aio.rs b/tests/aio.rs index 9753d4138..e721bf223 100644 --- a/tests/aio.rs +++ b/tests/aio.rs @@ -4,14 +4,13 @@ ))] #![cfg(all(feature = "os-poll", feature = "net"))] -use mio::{event::Source, Events, Interest, Poll, Registry, Token}; -use std::{ - fs::File, - io, mem, - os::unix::io::{AsRawFd, RawFd}, - pin::Pin, - ptr, -}; +use std::fs::File; +use std::os::unix::io::{AsRawFd, RawFd}; +use std::pin::Pin; +use std::{io, mem, ptr}; + +use mio::event::Source; +use mio::{Events, Interest, Poll, Registry, Token}; mod util; use util::{expect_events, expect_no_events, init, temp_file, ExpectEvent}; diff --git a/tests/close_on_drop.rs b/tests/close_on_drop.rs index 058761a89..74cc6f1c1 100644 --- a/tests/close_on_drop.rs +++ b/tests/close_on_drop.rs @@ -10,7 +10,7 @@ use mio::{Events, Interest, Poll, Registry, Token}; mod util; use util::{any_local_address, init}; -use self::TestState::{AfterRead, Initial}; +use TestState::{AfterRead, Initial}; const SERVER: Token = Token(0); const CLIENT: Token = Token(1); diff --git a/tests/poll.rs b/tests/poll.rs index a13e360c1..a829f72c9 100644 --- a/tests/poll.rs +++ b/tests/poll.rs @@ -1,11 +1,10 @@ #![cfg(not(target_os = "wasi"))] #![cfg(all(feature = "os-poll", feature = "net"))] -use std::net; use std::sync::{Arc, Barrier}; use std::thread::{self, sleep}; use std::time::Duration; -use std::{fmt, io}; +use std::{fmt, io, net}; use mio::event::Source; use mio::net::{TcpListener, TcpStream, UdpSocket}; @@ -115,11 +114,11 @@ fn poll_closes_fd() { fn drop_cancels_interest_and_shuts_down() { init(); - use mio::net::TcpStream; - use std::io; use std::io::Read; use std::net::TcpListener; - use std::thread; + use std::{io, thread}; + + use mio::net::TcpStream; let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); diff --git a/tests/tcp.rs b/tests/tcp.rs index 2c61403d5..b99abdbd6 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -1,14 +1,15 @@ #![cfg(not(target_os = "wasi"))] #![cfg(all(feature = "os-poll", feature = "net"))] -use mio::net::{TcpListener, TcpStream}; -use mio::{Events, Interest, Poll, Token}; use std::io::{self, Read, Write}; use std::net::{self, Shutdown}; use std::sync::mpsc::channel; use std::thread::{self, sleep}; use std::time::Duration; +use mio::net::{TcpListener, TcpStream}; +use mio::{Events, Interest, Poll, Token}; + #[macro_use] mod util; use util::{ @@ -23,7 +24,6 @@ const SERVER: Token = Token(2); #[test] #[cfg(all(unix, not(mio_unsupported_force_poll_poll), not(debug_assertions)))] fn assert_size() { - use mio::net::*; use std::mem::size_of; // Without debug assertions enabled `TcpListener`, `TcpStream` and diff --git a/tests/tcp_listener.rs b/tests/tcp_listener.rs index c927c3164..10e581bdf 100644 --- a/tests/tcp_listener.rs +++ b/tests/tcp_listener.rs @@ -1,8 +1,6 @@ #![cfg(not(target_os = "wasi"))] #![cfg(all(feature = "os-poll", feature = "net"))] -use mio::net::TcpListener; -use mio::{Interest, Token}; use std::io::{self, Read}; use std::net::{self, SocketAddr}; #[cfg(unix)] @@ -10,6 +8,9 @@ use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd}; use std::sync::{Arc, Barrier}; use std::thread; +use mio::net::TcpListener; +use mio::{Interest, Token}; + mod util; use util::{ any_local_address, any_local_ipv6_address, assert_send, assert_socket_close_on_exec, diff --git a/tests/tcp_stream.rs b/tests/tcp_stream.rs index f3d086544..f5e0cdd84 100644 --- a/tests/tcp_stream.rs +++ b/tests/tcp_stream.rs @@ -5,7 +5,8 @@ use std::io::{self, IoSlice, IoSliceMut, Read, Write}; use std::net::{self, Shutdown, SocketAddr}; #[cfg(unix)] use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd}; -use std::sync::{mpsc::channel, Arc, Barrier}; +use std::sync::mpsc::channel; +use std::sync::{Arc, Barrier}; use std::thread; use std::time::Duration; diff --git a/tests/udp_socket.rs b/tests/udp_socket.rs index ac82077ef..a1544d878 100644 --- a/tests/udp_socket.rs +++ b/tests/udp_socket.rs @@ -1,16 +1,16 @@ #![cfg(not(target_os = "wasi"))] #![cfg(all(feature = "os-poll", feature = "net"))] -use log::{debug, info}; -use mio::net::UdpSocket; -use mio::{Events, Interest, Poll, Registry, Token}; use std::net::{self, IpAddr, SocketAddr}; #[cfg(unix)] use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd}; -use std::str; use std::sync::{Arc, Barrier}; -use std::thread; use std::time::Duration; +use std::{str, thread}; + +use log::{debug, info}; +use mio::net::UdpSocket; +use mio::{Events, Interest, Poll, Registry, Token}; #[macro_use] mod util; @@ -32,7 +32,6 @@ const ID3: Token = Token(4); #[test] #[cfg(all(unix, not(mio_unsupported_force_poll_poll), not(debug_assertions)))] fn assert_size() { - use mio::net::*; use std::mem::size_of; // Without debug assertions enabled `TcpListener`, `TcpStream` and diff --git a/tests/unix_datagram.rs b/tests/unix_datagram.rs index 31784051c..a0e8bcf35 100644 --- a/tests/unix_datagram.rs +++ b/tests/unix_datagram.rs @@ -1,11 +1,12 @@ #![cfg(all(unix, feature = "os-poll", feature = "net"))] -use mio::net::UnixDatagram; -use mio::{Interest, Token}; use std::io; use std::net::Shutdown; use std::os::unix::net; +use mio::net::UnixDatagram; +use mio::{Interest, Token}; + #[macro_use] mod util; use util::{ diff --git a/tests/unix_listener.rs b/tests/unix_listener.rs index d1d9cf07d..03b01ee2d 100644 --- a/tests/unix_listener.rs +++ b/tests/unix_listener.rs @@ -1,13 +1,14 @@ #![cfg(all(unix, feature = "os-poll", feature = "net"))] -use mio::net::UnixListener; -use mio::{Interest, Token}; use std::io::{self, Read}; use std::os::unix::net; use std::path::{Path, PathBuf}; use std::sync::{Arc, Barrier}; use std::thread; +use mio::net::UnixListener; +use mio::{Interest, Token}; + #[macro_use] mod util; use util::{ diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index ecafa5440..731e282e3 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -1,7 +1,5 @@ #![cfg(all(unix, feature = "os-poll", feature = "net"))] -use mio::net::UnixStream; -use mio::{Interest, Token}; use std::io::{self, IoSlice, IoSliceMut, Read, Write}; use std::net::Shutdown; use std::os::unix::net; @@ -10,6 +8,9 @@ use std::sync::mpsc::channel; use std::sync::{Arc, Barrier}; use std::thread; +use mio::net::UnixStream; +use mio::{Interest, Token}; + #[macro_use] mod util; use util::{ diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 08c665c31..6f848fcf6 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -273,6 +273,7 @@ pub fn set_linger_zero(socket: &TcpStream) { #[cfg(windows)] pub fn set_linger_zero(socket: &TcpStream) { use std::os::windows::io::AsRawSocket; + use windows_sys::Win32::Networking::WinSock::{ setsockopt, LINGER, SOCKET_ERROR, SOL_SOCKET, SO_LINGER, }; diff --git a/tests/waker.rs b/tests/waker.rs index 0893b0fd3..5a70073da 100644 --- a/tests/waker.rs +++ b/tests/waker.rs @@ -1,11 +1,12 @@ #![cfg(not(target_os = "wasi"))] #![cfg(all(feature = "os-poll", feature = "net"))] -use mio::{Events, Poll, Token, Waker}; use std::sync::{Arc, Barrier}; use std::thread; use std::time::Duration; +use mio::{Events, Poll, Token, Waker}; + mod util; use util::{assert_send, assert_sync, expect_no_events, init}; diff --git a/tests/win_named_pipe.rs b/tests/win_named_pipe.rs index e79d2fba4..2f2cdf7a0 100644 --- a/tests/win_named_pipe.rs +++ b/tests/win_named_pipe.rs @@ -9,7 +9,8 @@ use std::time::Duration; use mio::windows::NamedPipe; use mio::{Events, Interest, Poll, Token}; use rand::Rng; -use windows_sys::Win32::{Foundation::ERROR_NO_DATA, Storage::FileSystem::FILE_FLAG_OVERLAPPED}; +use windows_sys::Win32::Foundation::ERROR_NO_DATA; +use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OVERLAPPED; fn _assert_kinds() { fn _assert_send() {}