Skip to content

Commit

Permalink
ci: Make rustfmt and clippy happy (#279)
Browse files Browse the repository at this point in the history
* chore: Make rustfmt happy

Signed-off-by: Xuanwo <[email protected]>

* Fix all clippy on linux

Signed-off-by: Xuanwo <[email protected]>

* Fix windows

Signed-off-by: Xuanwo <[email protected]>

* address more

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Aug 2, 2024
1 parent dbdb3d8 commit 874bcb1
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 51 deletions.
2 changes: 1 addition & 1 deletion monoio-compat/src/box_future.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 3 additions & 0 deletions monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'] }
2 changes: 1 addition & 1 deletion monoio/src/driver/legacy/iocp/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions monoio/src/driver/op/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _)
};
Expand Down
4 changes: 3 additions & 1 deletion monoio/src/driver/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions monoio/src/driver/shared_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
Expand Down
9 changes: 3 additions & 6 deletions monoio/src/fs/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions monoio/src/fs/metadata/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions monoio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
13 changes: 6 additions & 7 deletions monoio/src/macros/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@
/// 2. Aggregate the `<async expression>`s from each branch, including the disabled ones. If the
/// branch is disabled, `<async expression>` is still evaluated, but the resulting future is not
/// polled.
/// 3. Concurrently await on the results for all remaining `<async
/// expression>`s. 4. Once an `<async expression>` returns a value, attempt to
/// apply the value to the provided `<pattern>`, if the pattern matches,
/// evaluate `<handler>` 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 `<async expression>`s. 4. Once an `<async
/// expression>` returns a value, attempt to apply the value to the provided `<pattern>`, if
/// the pattern matches, evaluate `<handler>` 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
///
Expand Down
6 changes: 2 additions & 4 deletions monoio/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
});

Expand Down Expand Up @@ -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
})
}
3 changes: 1 addition & 2 deletions monoio/src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ impl TcpListener {
.as_ref()
.unwrap()
.local_addr()
.map(|addr| {
.inspect(|&addr| {
unsafe { &mut *meta }.local_addr = Some(addr);
addr
})
}

Expand Down
8 changes: 0 additions & 8 deletions monoio/src/time/driver/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
let cur_state = self.state.get();
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions monoio/src/time/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<Duration>) -> io::Result<()> {
let mut inner_state = self.handle.get().state.borrow_mut();

Expand Down
2 changes: 1 addition & 1 deletion monoio/src/utils/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<T> Drop for Page<T> {
} else {
// slow drop
to_drop.set_len(self.initialized);
std::mem::transmute::<_, Vec<Entry<T>>>(to_drop);
std::mem::transmute::<Vec<MaybeUninit<Entry<T>>>, Vec<Entry<T>>>(to_drop);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions monoio/tests/buf_writter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand Down

0 comments on commit 874bcb1

Please sign in to comment.