Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various Clippy lints #1777

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/tcp_listenfd_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/unix/selector/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Selector {

pub fn select(&self, events: &mut Events, timeout: Option<Duration>) -> 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
Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ fn poll(fds: &mut [PollFd], timeout: Option<Duration>) -> io::Result<usize> {
#[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| {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/iocp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl CompletionPort {
);
let mut removed = 0;
let timeout = duration_millis(timeout);
let len = cmp::min(list.len(), <u32>::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(),
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ fn connect_error() {
}

#[test]
#[allow(clippy::unused_io_amount)]
fn write_error() {
init();

Expand Down