From df59ff6e66872d60e11de3a9f3f6cedb74e16aed Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 24 Apr 2024 18:05:46 +0200 Subject: [PATCH 1/5] Replace max_value with MAX constant Fixes clippy::legacy_numeric_constants. Backport of commit 38149ae1b844c7547edd70ccbe339f38d4c17ff0, pr #1776. --- src/sys/unix/selector/epoll.rs | 2 +- src/sys/unix/selector/kqueue.rs | 2 +- src/sys/unix/selector/poll.rs | 2 +- src/sys/unix/tcp.rs | 2 +- src/sys/wasi/mod.rs | 2 +- src/sys/windows/iocp.rs | 2 +- src/sys/windows/tcp.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sys/unix/selector/epoll.rs b/src/sys/unix/selector/epoll.rs index c0a8a4c16..5c5302e35 100644 --- a/src/sys/unix/selector/epoll.rs +++ b/src/sys/unix/selector/epoll.rs @@ -77,7 +77,7 @@ impl Selector { #[cfg(target_pointer_width = "32")] const MAX_SAFE_TIMEOUT: u128 = 1789569; #[cfg(not(target_pointer_width = "32"))] - const MAX_SAFE_TIMEOUT: u128 = libc::c_int::max_value() as u128; + const MAX_SAFE_TIMEOUT: u128 = libc::c_int::MAX as u128; let timeout = timeout .map(|to| { diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index 0a2a24a57..8e5e41025 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -92,7 +92,7 @@ impl Selector { pub fn select(&self, events: &mut Events, timeout: Option) -> io::Result<()> { let timeout = timeout.map(|to| libc::timespec { - tv_sec: cmp::min(to.as_secs(), libc::time_t::max_value() as u64) as libc::time_t, + tv_sec: cmp::min(to.as_secs(), libc::time_t::MAX as u64) as libc::time_t, // `Duration::subsec_nanos` is guaranteed to be less than one // billion (the number of nanoseconds in a second), making the // cast to i32 safe. The cast itself is needed for platforms diff --git a/src/sys/unix/selector/poll.rs b/src/sys/unix/selector/poll.rs index cfafbc182..c8b0c6d20 100644 --- a/src/sys/unix/selector/poll.rs +++ b/src/sys/unix/selector/poll.rs @@ -504,7 +504,7 @@ fn poll(fds: &mut [PollFd], timeout: Option) -> io::Result { #[cfg(target_pointer_width = "32")] const MAX_SAFE_TIMEOUT: u128 = 1789569; #[cfg(not(target_pointer_width = "32"))] - const MAX_SAFE_TIMEOUT: u128 = libc::c_int::max_value() as u128; + const MAX_SAFE_TIMEOUT: u128 = libc::c_int::MAX as u128; let timeout = timeout .map(|to| { diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 6f755e870..1e3aac352 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -34,7 +34,7 @@ pub(crate) fn connect(socket: &net::TcpStream, addr: SocketAddr) -> io::Result<( } pub(crate) fn listen(socket: &net::TcpListener, backlog: u32) -> io::Result<()> { - let backlog = backlog.try_into().unwrap_or(i32::max_value()); + let backlog = backlog.try_into().unwrap_or(i32::MAX); syscall!(listen(socket.as_raw_fd(), backlog))?; Ok(()) } diff --git a/src/sys/wasi/mod.rs b/src/sys/wasi/mod.rs index b1a25fc9d..596d365d9 100644 --- a/src/sys/wasi/mod.rs +++ b/src/sys/wasi/mod.rs @@ -207,7 +207,7 @@ impl Selector { } /// Token used to a add a timeout subscription, also used in removing it again. -const TIMEOUT_TOKEN: wasi::Userdata = wasi::Userdata::max_value(); +const TIMEOUT_TOKEN: wasi::Userdata = wasi::Userdata::MAX; /// Returns a `wasi::Subscription` for `timeout`. fn timeout_subscription(timeout: Duration) -> wasi::Subscription { diff --git a/src/sys/windows/iocp.rs b/src/sys/windows/iocp.rs index c71b695d4..0590bb43f 100644 --- a/src/sys/windows/iocp.rs +++ b/src/sys/windows/iocp.rs @@ -96,7 +96,7 @@ impl CompletionPort { ); let mut removed = 0; let timeout = duration_millis(timeout); - let len = cmp::min(list.len(), ::max_value() as usize) as u32; + let len = cmp::min(list.len(), u32::MAX as usize) as u32; let ret = unsafe { GetQueuedCompletionStatusEx( self.handle.raw(), diff --git a/src/sys/windows/tcp.rs b/src/sys/windows/tcp.rs index addd1e8d8..4f77d5d6e 100644 --- a/src/sys/windows/tcp.rs +++ b/src/sys/windows/tcp.rs @@ -50,7 +50,7 @@ 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()); + let backlog = backlog.try_into().unwrap_or(i32::MAX); syscall!( listen(socket.as_raw_socket() as _, backlog), PartialEq::eq, From a508c7867dfead639e21398821944e553a628bd1 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 24 Apr 2024 18:09:24 +0200 Subject: [PATCH 2/5] Remove unneeded import Fixes clippy::legacy_numeric_constants. --- src/sys/unix/selector/epoll.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/unix/selector/epoll.rs b/src/sys/unix/selector/epoll.rs index 5c5302e35..97bb050cc 100644 --- a/src/sys/unix/selector/epoll.rs +++ b/src/sys/unix/selector/epoll.rs @@ -5,7 +5,7 @@ use std::os::unix::io::{AsRawFd, RawFd}; #[cfg(debug_assertions)] use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; -use std::{cmp, i32, io, ptr}; +use std::{cmp, io, ptr}; /// Unique id for use as `SelectorId`. #[cfg(debug_assertions)] From ab2ab15da76d2636391274a04952c25c637fab55 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 24 Apr 2024 18:23:31 +0200 Subject: [PATCH 3/5] Silence clippy::unused_io_amount in various places Way too many false positives. Backport of 8a1bfe148bdb709f7f0e43e0848dfa78c2561bea --- examples/tcp_listenfd_server.rs | 1 + src/sys/unix/waker.rs | 2 ++ tests/tcp.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/examples/tcp_listenfd_server.rs b/examples/tcp_listenfd_server.rs index 941d7f048..38b10d0ef 100644 --- a/examples/tcp_listenfd_server.rs +++ b/examples/tcp_listenfd_server.rs @@ -125,6 +125,7 @@ fn next(current: &mut Token) -> Token { } /// Returns `true` if the connection is done. +#[allow(clippy::unused_io_amount)] fn handle_connection_event( registry: &Registry, connection: &mut TcpStream, diff --git a/src/sys/unix/waker.rs b/src/sys/unix/waker.rs index 968f1a876..4642996fa 100644 --- a/src/sys/unix/waker.rs +++ b/src/sys/unix/waker.rs @@ -100,6 +100,7 @@ mod eventfd { Ok(WakerInternal { fd: file }) } + #[allow(clippy::unused_io_amount)] pub fn wake(&self) -> io::Result<()> { let buf: [u8; 8] = 1u64.to_ne_bytes(); match (&self.fd).write(&buf) { @@ -120,6 +121,7 @@ mod eventfd { } /// Reset the eventfd object, only need to call this if `wake` fails. + #[allow(clippy::unused_io_amount)] fn reset(&self) -> io::Result<()> { let mut buf: [u8; 8] = 0u64.to_ne_bytes(); match (&self.fd).read(&mut buf) { diff --git a/tests/tcp.rs b/tests/tcp.rs index 2c61403d5..87ef2329d 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -584,6 +584,7 @@ fn connect_error() { } #[test] +#[allow(clippy::unused_io_amount)] fn write_error() { init(); From a01ec84e0f1d1de6083d5bd382a753e4c449e0d8 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Thu, 25 Apr 2024 12:11:20 +0200 Subject: [PATCH 4/5] Ignore clippy::unused_io_amount in one more test --- tests/close_on_drop.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/close_on_drop.rs b/tests/close_on_drop.rs index 058761a89..7a5fc26f1 100644 --- a/tests/close_on_drop.rs +++ b/tests/close_on_drop.rs @@ -38,6 +38,7 @@ impl TestHandler { } } + #[allow(clippy::unused_io_amount)] fn handle_read(&mut self, registry: &Registry, tok: Token) { debug!("readable; tok={:?}", tok); From 14e083549ac325e19fc68d355af0efcb5ec9e4c4 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Thu, 25 Apr 2024 12:30:17 +0200 Subject: [PATCH 5/5] Ignore clippy::unused_io_amount in example --- examples/tcp_server.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/tcp_server.rs b/examples/tcp_server.rs index 21e2f2a82..b7d1ab410 100644 --- a/examples/tcp_server.rs +++ b/examples/tcp_server.rs @@ -105,6 +105,7 @@ fn next(current: &mut Token) -> Token { } /// Returns `true` if the connection is done. +#[allow(clippy::unused_io_amount)] fn handle_connection_event( registry: &Registry, connection: &mut TcpStream,