From 874bcb180027c3490f3d284d03c05a174650685a Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Fri, 2 Aug 2024 16:03:13 +0800 Subject: [PATCH] ci: Make rustfmt and clippy happy (#279) * chore: Make rustfmt happy Signed-off-by: Xuanwo * Fix all clippy on linux Signed-off-by: Xuanwo * Fix windows Signed-off-by: Xuanwo * address more Signed-off-by: Xuanwo --------- Signed-off-by: Xuanwo --- monoio-compat/src/box_future.rs | 2 +- monoio/Cargo.toml | 3 +++ monoio/src/driver/legacy/iocp/core.rs | 2 +- monoio/src/driver/op/accept.rs | 3 +-- monoio/src/driver/ready.rs | 4 +++- monoio/src/driver/shared_fd.rs | 6 ++---- monoio/src/fs/metadata/mod.rs | 9 +++------ monoio/src/fs/metadata/windows.rs | 1 + monoio/src/lib.rs | 1 + monoio/src/macros/select.rs | 13 ++++++------- monoio/src/net/mod.rs | 6 ++---- monoio/src/net/tcp/listener.rs | 3 +-- monoio/src/time/driver/entry.rs | 8 -------- monoio/src/time/driver/mod.rs | 11 ----------- monoio/src/utils/slab.rs | 2 +- monoio/tests/buf_writter.rs | 6 +++--- 16 files changed, 29 insertions(+), 51 deletions(-) diff --git a/monoio-compat/src/box_future.rs b/monoio-compat/src/box_future.rs index c51cf093..dab601af 100644 --- a/monoio-compat/src/box_future.rs +++ b/monoio-compat/src/box_future.rs @@ -1,7 +1,7 @@ use std::{future::Future, io}; use monoio::BufResult; -use reusable_box_future::{ReusableLocalBoxFuture, ReusableBoxFuture}; +use reusable_box_future::{ReusableBoxFuture, ReusableLocalBoxFuture}; use crate::buf::{Buf, RawBuf}; diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml index e7cbc77c..51437299 100644 --- a/monoio/Cargo.toml +++ b/monoio/Cargo.toml @@ -90,3 +90,6 @@ signal = ["ctrlc", "sync"] signal-termination = ["signal", "ctrlc/termination"] # by default both iouring and legacy are enabled default = ["async-cancel", "bytes", "iouring", "legacy", "macros", "utils"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] } diff --git a/monoio/src/driver/legacy/iocp/core.rs b/monoio/src/driver/legacy/iocp/core.rs index d871fd10..0c5cb4f1 100644 --- a/monoio/src/driver/legacy/iocp/core.rs +++ b/monoio/src/driver/legacy/iocp/core.rs @@ -47,7 +47,7 @@ impl CompletionPort { GetQueuedCompletionStatusEx( self.handle, entries.as_mut_ptr(), - std::cmp::min(entries.len(), u32::max_value() as usize) as u32, + std::cmp::min(entries.len(), u32::MAX as usize) as u32, &mut count, duration_millis(timeout), 0, diff --git a/monoio/src/driver/op/accept.rs b/monoio/src/driver/op/accept.rs index 0b17fd50..e683ed96 100644 --- a/monoio/src/driver/op/accept.rs +++ b/monoio/src/driver/op/accept.rs @@ -122,9 +122,8 @@ impl OpAble for Accept { let stream_fd = syscall_u32!(accept(fd, addr, len))? as i32; syscall_u32!(fcntl(stream_fd, libc::F_SETFD, libc::FD_CLOEXEC)) .and_then(|_| syscall_u32!(fcntl(stream_fd, libc::F_SETFL, libc::O_NONBLOCK))) - .map_err(|e| { + .inspect_err(|_| { let _ = syscall_u32!(close(stream_fd)); - e })?; Ok(stream_fd as _) }; diff --git a/monoio/src/driver/ready.rs b/monoio/src/driver/ready.rs index 6262359a..df25b8a3 100644 --- a/monoio/src/driver/ready.rs +++ b/monoio/src/driver/ready.rs @@ -73,7 +73,7 @@ impl Ready { pub(crate) fn from_mio(event: &mio::event::Event) -> Ready { let mut ready = Ready::EMPTY; - #[cfg(all(target_os = "freebsd", feature = "net"))] + #[cfg(all(target_os = "freebsd", feature = "legacy"))] { if event.is_aio() { ready |= Ready::READABLE; @@ -149,6 +149,8 @@ impl Ready { /// Specifies the readiness events the caller is interested in when awaiting on /// I/O resource readiness states. #[derive(Clone, Copy, Eq, PartialEq)] +// TODO: Do we need to remove it? +#[allow(dead_code)] pub(crate) struct Interest(mio::Interest); impl Interest { diff --git a/monoio/src/driver/shared_fd.rs b/monoio/src/driver/shared_fd.rs index 0cf550c4..b9f370fb 100644 --- a/monoio/src/driver/shared_fd.rs +++ b/monoio/src/driver/shared_fd.rs @@ -57,9 +57,8 @@ impl State { #[cfg(feature = "legacy")] crate::driver::Inner::Legacy(_) => panic!("unexpected legacy runtime"), }) - .map_err(|e| { + .inspect_err(|_| { let _ = crate::syscall!(fcntl(fd, libc::F_SETFL, 0)); - e })?; *state = UringState::Legacy(Some(reg)); } else { @@ -97,9 +96,8 @@ impl State { #[cfg(feature = "legacy")] crate::driver::Inner::Legacy(_) => panic!("unexpected legacy runtime"), }) - .map_err(|e| { + .inspect_err(|_| { let _ = crate::syscall!(fcntl(fd, libc::F_SETFL, libc::O_NONBLOCK)); - e })?; *self = State::Uring(UringState::Init); Ok(()) diff --git a/monoio/src/fs/metadata/mod.rs b/monoio/src/fs/metadata/mod.rs index ae0fc755..55359bf0 100644 --- a/monoio/src/fs/metadata/mod.rs +++ b/monoio/src/fs/metadata/mod.rs @@ -1,13 +1,10 @@ mod unix; mod windows; -use crate::driver::op::Op; +use std::{os::unix::fs::MetadataExt, path::Path, time::SystemTime}; -use super::file_type::FileType; -use super::permissions::Permissions; -use std::os::unix::fs::MetadataExt; -use std::path::Path; -use std::time::SystemTime; +use super::{file_type::FileType, permissions::Permissions}; +use crate::driver::op::Op; /// Given a path, query the file system to get information about a file, /// directory, etc. diff --git a/monoio/src/fs/metadata/windows.rs b/monoio/src/fs/metadata/windows.rs index e69de29b..8b137891 100644 --- a/monoio/src/fs/metadata/windows.rs +++ b/monoio/src/fs/metadata/windows.rs @@ -0,0 +1 @@ + diff --git a/monoio/src/lib.rs b/monoio/src/lib.rs index fee78ed6..20cbb72d 100644 --- a/monoio/src/lib.rs +++ b/monoio/src/lib.rs @@ -2,6 +2,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs, unreachable_pub)] #![allow(stable_features)] +#![allow(clippy::macro_metavars_in_unsafe)] #![cfg_attr(feature = "unstable", feature(io_error_more))] #![cfg_attr(feature = "unstable", feature(lazy_cell))] #![cfg_attr(feature = "unstable", feature(stmt_expr_attributes))] diff --git a/monoio/src/macros/select.rs b/monoio/src/macros/select.rs index 8736ac8f..ad602904 100644 --- a/monoio/src/macros/select.rs +++ b/monoio/src/macros/select.rs @@ -36,13 +36,12 @@ /// 2. Aggregate the ``s from each branch, including the disabled ones. If the /// branch is disabled, `` is still evaluated, but the resulting future is not /// polled. -/// 3. Concurrently await on the results for all remaining ``s. 4. Once an `` returns a value, attempt to -/// apply the value to the provided ``, if the pattern matches, -/// evaluate `` and return. If the pattern **does not** match, -/// disable the current branch and for the remainder of the current call to -/// `select!`. Continue from step 3. 5. If **all** branches are disabled, -/// evaluate the `else` expression. If no else branch is provided, panic. +/// 3. Concurrently await on the results for all remaining ``s. 4. Once an `` returns a value, attempt to apply the value to the provided ``, if +/// the pattern matches, evaluate `` and return. If the pattern **does not** match, +/// disable the current branch and for the remainder of the current call to `select!`. +/// Continue from step 3. 5. If **all** branches are disabled, evaluate the `else` expression. If +/// no else branch is provided, panic. /// /// # Runtime characteristics /// diff --git a/monoio/src/net/mod.rs b/monoio/src/net/mod.rs index 6f4eb5c9..7aa47a1d 100644 --- a/monoio/src/net/mod.rs +++ b/monoio/src/net/mod.rs @@ -77,11 +77,10 @@ pub(crate) fn new_socket( .and_then(|_| { crate::syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| socket) }) - .map_err(|e| { + .inspect_err(|_| { // If either of the `fcntl` calls failed, ensure the socket is // closed and return the error. let _ = crate::syscall!(close(socket)); - e }) }); @@ -116,13 +115,12 @@ pub(crate) fn new_socket( NO_ERROR as _ ) .map(|_: i32| socket as RawSocket) - .map_err(|e| { + .inspect_err(|_| { // If either of the `ioctlsocket` calls failed, ensure the socket is // closed and return the error. unsafe { closesocket(socket); WSACleanup(); } - e }) } diff --git a/monoio/src/net/tcp/listener.rs b/monoio/src/net/tcp/listener.rs index 70d04951..52b930f7 100644 --- a/monoio/src/net/tcp/listener.rs +++ b/monoio/src/net/tcp/listener.rs @@ -224,9 +224,8 @@ impl TcpListener { .as_ref() .unwrap() .local_addr() - .map(|addr| { + .inspect(|&addr| { unsafe { &mut *meta }.local_addr = Some(addr); - addr }) } diff --git a/monoio/src/time/driver/entry.rs b/monoio/src/time/driver/entry.rs index 83555749..2ab2337a 100644 --- a/monoio/src/time/driver/entry.rs +++ b/monoio/src/time/driver/entry.rs @@ -114,10 +114,6 @@ impl StateCell { } } - fn is_pending(&self) -> bool { - self.state.get() == STATE_PENDING_FIRE - } - /// Returns the current expiration time, or None if not currently scheduled. fn when(&self) -> Option { let cur_state = self.state.get(); @@ -525,10 +521,6 @@ impl TimerHandle { unsafe { self.inner.as_ref().sync_when() } } - pub(super) unsafe fn is_pending(&self) -> bool { - unsafe { self.inner.as_ref().state.is_pending() } - } - /// Forcibly sets the true and cached expiration times to the given tick. /// /// SAFETY: The caller must ensure that the handle remains valid, the driver diff --git a/monoio/src/time/driver/mod.rs b/monoio/src/time/driver/mod.rs index c270d4d7..3887dfe2 100644 --- a/monoio/src/time/driver/mod.rs +++ b/monoio/src/time/driver/mod.rs @@ -2,7 +2,6 @@ // in the future, this will change to the reverse. For now, suppress this // warning and generally stick with being explicit about unsafety. #![allow(unused_unsafe)] -#![cfg_attr(not(feature = "rt"), allow(dead_code))] //! Time driver @@ -173,16 +172,6 @@ where } } - /// Returns a handle to the timer. - /// - /// The `Handle` is how `Sleep` instances are created. The `Sleep` instances - /// can either be created directly or the `Handle` instance can be passed to - /// `with_default`, setting the timer as the default timer for the execution - /// context. - pub(crate) fn handle(&self) -> Handle { - self.handle.clone() - } - fn park_internal(&self, limit: Option) -> io::Result<()> { let mut inner_state = self.handle.get().state.borrow_mut(); diff --git a/monoio/src/utils/slab.rs b/monoio/src/utils/slab.rs index 58461137..651823dd 100644 --- a/monoio/src/utils/slab.rs +++ b/monoio/src/utils/slab.rs @@ -336,7 +336,7 @@ impl Drop for Page { } else { // slow drop to_drop.set_len(self.initialized); - std::mem::transmute::<_, Vec>>(to_drop); + std::mem::transmute::>>, Vec>>(to_drop); } } } diff --git a/monoio/tests/buf_writter.rs b/monoio/tests/buf_writter.rs index c1f9e00a..7d6f4310 100644 --- a/monoio/tests/buf_writter.rs +++ b/monoio/tests/buf_writter.rs @@ -13,9 +13,9 @@ async fn ensure_buf_writter_write_properly() { let (_, stream_write) = stream.into_split(); let mut buf_w = BufWriter::new(stream_write); - assert!(buf_w.write(&[b'1']).await.0.is_ok()); - assert!(buf_w.write(&[b'2']).await.0.is_ok()); - assert!(buf_w.write(&[b'3']).await.0.is_ok()); + assert!(buf_w.write(b"1").await.0.is_ok()); + assert!(buf_w.write(b"2").await.0.is_ok()); + assert!(buf_w.write(b"3").await.0.is_ok()); assert!(buf_w.flush().await.is_ok()); });