Skip to content

Commit 5ee597c

Browse files
authored
CI check clippy (#324)
2 parents fe17ef8 + 3a4f7b3 commit 5ee597c

File tree

16 files changed

+383
-38
lines changed

16 files changed

+383
-38
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ jobs:
2121
toolchain: ${{ matrix.target == 'i686-pc-windows-gnu' && format('{0}-i686-pc-windows-gnu', matrix.channel) || matrix.channel }}
2222
target: ${{ matrix.target }}
2323
override: true
24-
components: rustfmt
25-
- uses: actions-rs/cargo@v1
24+
components: rustfmt, clippy
25+
- name: Check code format
26+
uses: actions-rs/cargo@v1
2627
with:
2728
command: fmt
2829
args: --all -- --check
30+
- name: Check clippy with default features
31+
uses: actions-rs/cargo@v1
32+
with:
33+
command: clippy
34+
args: --all -- -D warnings
35+
- name: Check clippy with all features
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: clippy
39+
args: --all --all-features -- -D warnings
2940
- name: Run cargo deny
3041
if: ${{ contains(matrix.os, 'ubuntu') }}
3142
uses: EmbarkStudios/cargo-deny-action@v2

core/src/common/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub enum Syscall {
125125
SetFilePointerEx,
126126
#[cfg(windows)]
127127
WaitOnAddress,
128+
#[cfg(windows)]
129+
WSAPoll,
128130
}
129131

130132
impl Syscall {

core/src/coroutine/local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'c> CoroutineLocal<'c> {
1616
pub fn put<V>(&self, key: &'c str, val: V) -> Option<V> {
1717
let v = Box::leak(Box::new(val));
1818
self.0
19-
.insert(key, std::ptr::from_mut::<V>(v) as usize)
19+
.insert(key, std::ptr::from_mut(v) as usize)
2020
.map(|ptr| unsafe { *Box::from_raw((ptr as *mut c_void).cast::<V>()) })
2121
}
2222

core/src/net/event_loop.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'e> EventLoop<'e> {
123123
let syscall_mask = <Syscall as Into<&str>>::into(syscall).as_ptr() as usize;
124124
let token = thread_id as usize ^ syscall_mask;
125125
if Syscall::nio() != syscall {
126-
eprintln!("{syscall} {token}");
126+
eprintln!("generate token:{token} for {syscall}");
127127
}
128128
token
129129
}
@@ -255,8 +255,7 @@ impl<'e> EventLoop<'e> {
255255
continue;
256256
}
257257
// resolve completed read/write tasks
258-
let result = cqe.result() as c_longlong;
259-
eprintln!("io_uring finish {token} {result}");
258+
let result = c_longlong::from(cqe.result());
260259
if let Some((_, pair)) = self.syscall_wait_table.remove(&token) {
261260
let (lock, cvar) = &*pair;
262261
let mut pending = lock.lock().expect("lock failed");

core/src/net/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ use std::sync::atomic::{AtomicUsize, Ordering};
1111
use std::sync::{Arc, Condvar, Mutex};
1212
use std::time::Duration;
1313

14-
/// 做C兼容时会用到
15-
pub type UserFunc = extern "C" fn(usize) -> usize;
16-
1714
cfg_if::cfg_if! {
1815
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
1916
use libc::{epoll_event, iovec, msghdr, off_t, size_t, sockaddr, socklen_t};
2017
use std::ffi::{c_longlong, c_void};
2118
}
2219
}
2320

21+
/// 做C兼容时会用到
22+
pub type UserFunc = extern "C" fn(usize) -> usize;
23+
2424
mod selector;
2525

26-
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
26+
#[allow(
27+
clippy::cast_possible_truncation,
28+
clippy::cast_sign_loss,
29+
clippy::too_many_arguments
30+
)]
2731
#[cfg(all(target_os = "linux", feature = "io_uring"))]
2832
mod operator;
2933

core/src/net/operator/linux/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ impl Operator<'_> {
574574
)
575575
}
576576

577-
#[allow(clippy::too_many_arguments)]
578577
pub(crate) fn sendto(
579578
&self,
580579
user_data: usize,

core/src/syscall/unix/connect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
7474
{
7575
break;
7676
}
77-
let mut err: c_int = 0;
77+
let mut err = 0;
7878
unsafe {
7979
let mut len: socklen_t = std::mem::zeroed();
8080
r = libc::getsockopt(
8181
fd,
8282
libc::SOL_SOCKET,
8383
libc::SO_ERROR,
84-
(std::ptr::addr_of_mut!(err)).cast::<c_void>(),
84+
std::ptr::addr_of_mut!(err).cast::<c_void>(),
8585
&mut len,
8686
);
8787
}

core/src/syscall/unix/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ macro_rules! impl_facade {
2323
let new_state = $crate::common::constants::SyscallState::Executing;
2424
if co.syscall((), syscall, new_state).is_err() {
2525
$crate::error!("{} change to syscall {} {} failed !",
26-
co.name(), syscall, new_state);
26+
co.name(), syscall, new_state
27+
);
2728
}
2829
}
2930
let r = self.inner.$syscall(fn_ptr, $($arg, )*);
@@ -32,7 +33,7 @@ macro_rules! impl_facade {
3233
$crate::error!("{} change to running state failed !", co.name());
3334
}
3435
}
35-
$crate::info!("exit syscall {}", syscall);
36+
$crate::info!("exit syscall {} {:?}", syscall, r);
3637
r
3738
}
3839
}
@@ -66,9 +67,7 @@ macro_rules! impl_io_uring {
6667
if co.syscall((), syscall, new_state).is_err() {
6768
$crate::error!(
6869
"{} change to syscall {} {} failed !",
69-
co.name(),
70-
syscall,
71-
new_state
70+
co.name(), syscall, new_state
7271
);
7372
}
7473
}
@@ -84,9 +83,7 @@ macro_rules! impl_io_uring {
8483
if co.syscall((), syscall, new_state).is_err() {
8584
$crate::error!(
8685
"{} change to syscall {} {} failed !",
87-
co.name(),
88-
syscall,
89-
new_state
86+
co.name(), syscall, new_state
9087
);
9188
}
9289
}

core/src/syscall/unix/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<I: PollSyscall> PollSyscall for NioPollSyscall<I> {
4747
let mut t = if timeout < 0 { c_int::MAX } else { timeout };
4848
let mut x = 1;
4949
let mut r;
50-
// just check select every x ms
50+
// just check poll every x ms
5151
loop {
5252
r = self.inner.poll(fn_ptr, fds, nfds, 0);
5353
if r != 0 || t == 0 {

core/src/syscall/unix/select.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ trait SelectSyscall {
3535
}
3636

3737
impl_facade!(SelectSyscallFacade, SelectSyscall,
38-
select(nfds: c_int, readfds: *mut fd_set, writefds: *mut fd_set,
39-
errorfds: *mut fd_set, timeout: *mut timeval) -> c_int
38+
select(
39+
nfds: c_int,
40+
readfds: *mut fd_set,
41+
writefds: *mut fd_set,
42+
errorfds: *mut fd_set,
43+
timeout: *mut timeval
44+
) -> c_int
4045
);
4146

4247
#[repr(C)]
@@ -78,7 +83,7 @@ impl<I: SelectSyscall> SelectSyscall for NioSelectSyscall<I> {
7883
}
7984
let mut x = 1;
8085
let mut r;
81-
// just check poll every x ms
86+
// just check select every x ms
8287
loop {
8388
r = self
8489
.inner
@@ -111,6 +116,11 @@ impl<I: SelectSyscall> SelectSyscall for NioSelectSyscall<I> {
111116
}
112117

113118
impl_raw!(RawSelectSyscall, SelectSyscall,
114-
select(nfds: c_int, readfds: *mut fd_set, writefds: *mut fd_set,
115-
errorfds: *mut fd_set, timeout: *mut timeval) -> c_int
119+
select(
120+
nfds: c_int,
121+
readfds: *mut fd_set,
122+
writefds: *mut fd_set,
123+
errorfds: *mut fd_set,
124+
timeout: *mut timeval
125+
) -> c_int
116126
);

0 commit comments

Comments
 (0)