Skip to content

Commit e9e91ff

Browse files
committed
Fix Clippy warnings on Windows
Seems this isn't check on the CI.
1 parent b48cce6 commit e9e91ff

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

src/sys/windows/afd.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ cfg_io_source! {
180180
&AFD_HELPER_ATTRIBUTES as *const _ as *mut _,
181181
&mut iosb,
182182
null_mut(),
183-
0 as ULONG,
183+
0,
184184
FILE_SHARE_READ | FILE_SHARE_WRITE,
185185
FILE_OPEN,
186-
0 as ULONG,
186+
0,
187187
null_mut(),
188-
0 as ULONG,
188+
0,
189189
);
190190
if status != STATUS_SUCCESS {
191191
let raw_err = io::Error::from_raw_os_error(
@@ -214,18 +214,18 @@ cfg_io_source! {
214214
}
215215
}
216216

217-
pub const POLL_RECEIVE: u32 = 0b000_000_001;
218-
pub const POLL_RECEIVE_EXPEDITED: u32 = 0b000_000_010;
219-
pub const POLL_SEND: u32 = 0b000_000_100;
220-
pub const POLL_DISCONNECT: u32 = 0b000_001_000;
221-
pub const POLL_ABORT: u32 = 0b000_010_000;
222-
pub const POLL_LOCAL_CLOSE: u32 = 0b000_100_000;
217+
pub const POLL_RECEIVE: u32 = 0b0_0000_0001;
218+
pub const POLL_RECEIVE_EXPEDITED: u32 = 0b0_0000_0010;
219+
pub const POLL_SEND: u32 = 0b0_0000_0100;
220+
pub const POLL_DISCONNECT: u32 = 0b0_0000_1000;
221+
pub const POLL_ABORT: u32 = 0b0_0001_0000;
222+
pub const POLL_LOCAL_CLOSE: u32 = 0b0_0010_0000;
223223
// Not used as it indicated in each event where a connection is connected, not
224224
// just the first time a connection is established.
225225
// Also see https://github.com/piscisaureus/wepoll/commit/8b7b340610f88af3d83f40fb728e7b850b090ece.
226-
pub const POLL_CONNECT: u32 = 0b001_000_000;
227-
pub const POLL_ACCEPT: u32 = 0b010_000_000;
228-
pub const POLL_CONNECT_FAIL: u32 = 0b100_000_000;
226+
pub const POLL_CONNECT: u32 = 0b0_0100_0000;
227+
pub const POLL_ACCEPT: u32 = 0b0_1000_0000;
228+
pub const POLL_CONNECT_FAIL: u32 = 0b1_0000_0000;
229229

230230
pub const KNOWN_EVENTS: u32 = POLL_RECEIVE
231231
| POLL_RECEIVE_EXPEDITED

src/sys/windows/named_pipe.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,8 @@ impl Drop for NamedPipe {
467467
}
468468

469469
let io = self.inner.io.lock().unwrap();
470-
471-
match io.read {
472-
State::Pending(..) => {
473-
drop(cancel(&self.inner.handle, &self.inner.read));
474-
}
475-
_ => {}
470+
if let State::Pending(..) = io.read {
471+
drop(cancel(&self.inner.handle, &self.inner.read));
476472
}
477473
}
478474
}
@@ -587,7 +583,8 @@ impl Inner {
587583

588584
fn post_register(me: &Arc<Inner>, mut events: Option<&mut Vec<Event>>) {
589585
let mut io = me.io.lock().unwrap();
590-
if Inner::schedule_read(&me, &mut io, events.as_mut().map(|ptr| &mut **ptr)) {
586+
#[allow(clippy::needless_option_as_deref)]
587+
if Inner::schedule_read(me, &mut io, events.as_deref_mut()) {
591588
if let State::None = io.write {
592589
io.notify_writable(events);
593590
}

src/sys/windows/selector.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl AfdGroup {
4444

4545
pub fn release_unused_afd(&self) {
4646
let mut afd_group = self.afd_group.lock().unwrap();
47-
afd_group.retain(|g| Arc::strong_count(&g) > 1);
47+
afd_group.retain(|g| Arc::strong_count(g) > 1);
4848
}
4949
}
5050

@@ -58,7 +58,7 @@ cfg_io_source! {
5858
self._alloc_afd_group(&mut afd_group)?;
5959
} else {
6060
// + 1 reference in Vec
61-
if Arc::strong_count(afd_group.last().unwrap()) >= POLL_GROUP__MAX_GROUP_SIZE + 1 {
61+
if Arc::strong_count(afd_group.last().unwrap()) > POLL_GROUP__MAX_GROUP_SIZE {
6262
self._alloc_afd_group(&mut afd_group)?;
6363
}
6464
}
@@ -447,11 +447,11 @@ impl SelectorInner {
447447
if len == 0 {
448448
continue;
449449
}
450-
return Ok(());
450+
break Ok(());
451451
}
452452
} else {
453453
self.select2(&mut events.statuses, &mut events.events, timeout)?;
454-
return Ok(());
454+
Ok(())
455455
}
456456
}
457457

@@ -461,7 +461,7 @@ impl SelectorInner {
461461
events: &mut Vec<Event>,
462462
timeout: Option<Duration>,
463463
) -> io::Result<usize> {
464-
assert_eq!(self.is_polling.swap(true, Ordering::AcqRel), false);
464+
assert!(!self.is_polling.swap(true, Ordering::AcqRel));
465465

466466
unsafe { self.update_sockets_events() }?;
467467

@@ -481,7 +481,7 @@ impl SelectorInner {
481481
for sock in update_queue.iter_mut() {
482482
let mut sock_internal = sock.lock().unwrap();
483483
if !sock_internal.is_pending_deletion() {
484-
sock_internal.update(&sock)?;
484+
sock_internal.update(sock)?;
485485
}
486486
}
487487

@@ -517,12 +517,9 @@ impl SelectorInner {
517517

518518
let sock_state = from_overlapped(iocp_event.overlapped());
519519
let mut sock_guard = sock_state.lock().unwrap();
520-
match sock_guard.feed_event() {
521-
Some(e) => {
522-
events.push(e);
523-
n += 1;
524-
}
525-
None => {}
520+
if let Some(e) = sock_guard.feed_event() {
521+
events.push(e);
522+
n += 1;
526523
}
527524

528525
if !sock_guard.is_pending_deletion() {

tests/util/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,20 @@ pub fn set_linger_zero(socket: &TcpStream) {
269269
l_linger: 0,
270270
};
271271

272-
match unsafe {
272+
let res = unsafe {
273273
setsockopt(
274274
socket.as_raw_socket() as _,
275275
SOL_SOCKET,
276276
SO_LINGER,
277277
&val as *const _ as *const _,
278278
size_of::<linger>() as _,
279279
)
280-
} {
281-
SOCKET_ERROR => panic!("error setting linger: {}", io::Error::last_os_error()),
282-
_ => {}
283-
}
280+
};
281+
assert!(
282+
res != SOCKET_ERROR,
283+
"error setting linger: {}",
284+
io::Error::last_os_error()
285+
);
284286
}
285287

286288
/// Returns a path to a temporary file using `name` as filename.

tests/win_named_pipe.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ fn connect_before_client() {
121121

122122
let mut events = Events::with_capacity(128);
123123
t!(poll.poll(&mut events, Some(Duration::new(0, 0))));
124-
let e = events.iter().collect::<Vec<_>>();
125-
assert_eq!(e.len(), 0);
124+
assert_eq!(events.iter().count(), 0);
126125
assert_eq!(
127126
server.connect().err().unwrap().kind(),
128127
io::ErrorKind::WouldBlock
@@ -157,8 +156,7 @@ fn connect_after_client() {
157156

158157
let mut events = Events::with_capacity(128);
159158
t!(poll.poll(&mut events, Some(Duration::new(0, 0))));
160-
let e = events.iter().collect::<Vec<_>>();
161-
assert_eq!(e.len(), 0);
159+
assert_eq!(events.iter().count(), 0);
162160

163161
let mut client = client(&name);
164162
t!(poll.registry().register(

0 commit comments

Comments
 (0)