From e9e91ffeb31246f25d7ccdf781853632b3f00b72 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Tue, 28 Sep 2021 19:59:15 +0200 Subject: [PATCH] Fix Clippy warnings on Windows Seems this isn't check on the CI. --- src/sys/windows/afd.rs | 24 ++++++++++++------------ src/sys/windows/named_pipe.rs | 11 ++++------- src/sys/windows/selector.rs | 21 +++++++++------------ tests/util/mod.rs | 12 +++++++----- tests/win_named_pipe.rs | 6 ++---- 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/sys/windows/afd.rs b/src/sys/windows/afd.rs index 6241a45ef..6eae3bc03 100644 --- a/src/sys/windows/afd.rs +++ b/src/sys/windows/afd.rs @@ -180,12 +180,12 @@ cfg_io_source! { &AFD_HELPER_ATTRIBUTES as *const _ as *mut _, &mut iosb, null_mut(), - 0 as ULONG, + 0, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, - 0 as ULONG, + 0, null_mut(), - 0 as ULONG, + 0, ); if status != STATUS_SUCCESS { let raw_err = io::Error::from_raw_os_error( @@ -214,18 +214,18 @@ cfg_io_source! { } } -pub const POLL_RECEIVE: u32 = 0b000_000_001; -pub const POLL_RECEIVE_EXPEDITED: u32 = 0b000_000_010; -pub const POLL_SEND: u32 = 0b000_000_100; -pub const POLL_DISCONNECT: u32 = 0b000_001_000; -pub const POLL_ABORT: u32 = 0b000_010_000; -pub const POLL_LOCAL_CLOSE: u32 = 0b000_100_000; +pub const POLL_RECEIVE: u32 = 0b0_0000_0001; +pub const POLL_RECEIVE_EXPEDITED: u32 = 0b0_0000_0010; +pub const POLL_SEND: u32 = 0b0_0000_0100; +pub const POLL_DISCONNECT: u32 = 0b0_0000_1000; +pub const POLL_ABORT: u32 = 0b0_0001_0000; +pub const POLL_LOCAL_CLOSE: u32 = 0b0_0010_0000; // Not used as it indicated in each event where a connection is connected, not // just the first time a connection is established. // Also see https://github.com/piscisaureus/wepoll/commit/8b7b340610f88af3d83f40fb728e7b850b090ece. -pub const POLL_CONNECT: u32 = 0b001_000_000; -pub const POLL_ACCEPT: u32 = 0b010_000_000; -pub const POLL_CONNECT_FAIL: u32 = 0b100_000_000; +pub const POLL_CONNECT: u32 = 0b0_0100_0000; +pub const POLL_ACCEPT: u32 = 0b0_1000_0000; +pub const POLL_CONNECT_FAIL: u32 = 0b1_0000_0000; pub const KNOWN_EVENTS: u32 = POLL_RECEIVE | POLL_RECEIVE_EXPEDITED diff --git a/src/sys/windows/named_pipe.rs b/src/sys/windows/named_pipe.rs index b2eca464a..adda51f23 100644 --- a/src/sys/windows/named_pipe.rs +++ b/src/sys/windows/named_pipe.rs @@ -467,12 +467,8 @@ impl Drop for NamedPipe { } let io = self.inner.io.lock().unwrap(); - - match io.read { - State::Pending(..) => { - drop(cancel(&self.inner.handle, &self.inner.read)); - } - _ => {} + if let State::Pending(..) = io.read { + drop(cancel(&self.inner.handle, &self.inner.read)); } } } @@ -587,7 +583,8 @@ impl Inner { fn post_register(me: &Arc, mut events: Option<&mut Vec>) { let mut io = me.io.lock().unwrap(); - if Inner::schedule_read(&me, &mut io, events.as_mut().map(|ptr| &mut **ptr)) { + #[allow(clippy::needless_option_as_deref)] + if Inner::schedule_read(me, &mut io, events.as_deref_mut()) { if let State::None = io.write { io.notify_writable(events); } diff --git a/src/sys/windows/selector.rs b/src/sys/windows/selector.rs index 6d9234753..133fefe89 100644 --- a/src/sys/windows/selector.rs +++ b/src/sys/windows/selector.rs @@ -44,7 +44,7 @@ impl AfdGroup { pub fn release_unused_afd(&self) { let mut afd_group = self.afd_group.lock().unwrap(); - afd_group.retain(|g| Arc::strong_count(&g) > 1); + afd_group.retain(|g| Arc::strong_count(g) > 1); } } @@ -58,7 +58,7 @@ cfg_io_source! { self._alloc_afd_group(&mut afd_group)?; } else { // + 1 reference in Vec - if Arc::strong_count(afd_group.last().unwrap()) >= POLL_GROUP__MAX_GROUP_SIZE + 1 { + if Arc::strong_count(afd_group.last().unwrap()) > POLL_GROUP__MAX_GROUP_SIZE { self._alloc_afd_group(&mut afd_group)?; } } @@ -447,11 +447,11 @@ impl SelectorInner { if len == 0 { continue; } - return Ok(()); + break Ok(()); } } else { self.select2(&mut events.statuses, &mut events.events, timeout)?; - return Ok(()); + Ok(()) } } @@ -461,7 +461,7 @@ impl SelectorInner { events: &mut Vec, timeout: Option, ) -> io::Result { - assert_eq!(self.is_polling.swap(true, Ordering::AcqRel), false); + assert!(!self.is_polling.swap(true, Ordering::AcqRel)); unsafe { self.update_sockets_events() }?; @@ -481,7 +481,7 @@ impl SelectorInner { for sock in update_queue.iter_mut() { let mut sock_internal = sock.lock().unwrap(); if !sock_internal.is_pending_deletion() { - sock_internal.update(&sock)?; + sock_internal.update(sock)?; } } @@ -517,12 +517,9 @@ impl SelectorInner { let sock_state = from_overlapped(iocp_event.overlapped()); let mut sock_guard = sock_state.lock().unwrap(); - match sock_guard.feed_event() { - Some(e) => { - events.push(e); - n += 1; - } - None => {} + if let Some(e) = sock_guard.feed_event() { + events.push(e); + n += 1; } if !sock_guard.is_pending_deletion() { diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 9b1d12633..7d54da232 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -269,7 +269,7 @@ pub fn set_linger_zero(socket: &TcpStream) { l_linger: 0, }; - match unsafe { + let res = unsafe { setsockopt( socket.as_raw_socket() as _, SOL_SOCKET, @@ -277,10 +277,12 @@ pub fn set_linger_zero(socket: &TcpStream) { &val as *const _ as *const _, size_of::() as _, ) - } { - SOCKET_ERROR => panic!("error setting linger: {}", io::Error::last_os_error()), - _ => {} - } + }; + assert!( + res != SOCKET_ERROR, + "error setting linger: {}", + io::Error::last_os_error() + ); } /// Returns a path to a temporary file using `name` as filename. diff --git a/tests/win_named_pipe.rs b/tests/win_named_pipe.rs index 5d4d3022d..e1451f0df 100644 --- a/tests/win_named_pipe.rs +++ b/tests/win_named_pipe.rs @@ -121,8 +121,7 @@ fn connect_before_client() { let mut events = Events::with_capacity(128); t!(poll.poll(&mut events, Some(Duration::new(0, 0)))); - let e = events.iter().collect::>(); - assert_eq!(e.len(), 0); + assert_eq!(events.iter().count(), 0); assert_eq!( server.connect().err().unwrap().kind(), io::ErrorKind::WouldBlock @@ -157,8 +156,7 @@ fn connect_after_client() { let mut events = Events::with_capacity(128); t!(poll.poll(&mut events, Some(Duration::new(0, 0)))); - let e = events.iter().collect::>(); - assert_eq!(e.len(), 0); + assert_eq!(events.iter().count(), 0); let mut client = client(&name); t!(poll.registry().register(