Skip to content

Commit 1efdce3

Browse files
committed
fix clippy
1 parent ff572d3 commit 1efdce3

File tree

9 files changed

+24
-43
lines changed

9 files changed

+24
-43
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::common::constants::SyscallName;
22
use crate::common::{get_timeout_time, now};
33
use crate::impl_display_by_debug;
44
use std::ffi::{c_int, c_longlong, c_uint};
5-
use std::io::{Error, ErrorKind};
5+
use std::io::ErrorKind;
66
use std::marker::PhantomData;
77
use std::sync::atomic::{AtomicBool, Ordering};
88
use std::time::{Duration, Instant};
@@ -239,7 +239,7 @@ impl<'o> Operator<'o> {
239239
&mut sock_info_len,
240240
) != 0
241241
{
242-
return Err(Error::new(ErrorKind::Other, "get socket info failed"));
242+
return Err(Error::other("get socket info failed"));
243243
}
244244
self.add_handle(fd as HANDLE)?;
245245
let socket = WSASocketW(
@@ -251,10 +251,7 @@ impl<'o> Operator<'o> {
251251
WSA_FLAG_OVERLAPPED,
252252
);
253253
if INVALID_SOCKET == socket {
254-
return Err(Error::new(
255-
ErrorKind::Other,
256-
format!("add {syscall_name} operation failed"),
257-
));
254+
return Err(Error::other(format!("add {syscall_name} operation failed")));
258255
}
259256
let size = size_of::<SOCKADDR_IN>()
260257
.saturating_add(16)
@@ -370,10 +367,9 @@ impl<'o> Operator<'o> {
370367
{
371368
let errno = WSAGetLastError();
372369
if WSA_IO_PENDING != errno {
373-
return Err(Error::new(
374-
ErrorKind::Other,
375-
format!("add {syscall_name} operation failed with {errno}"),
376-
));
370+
return Err(Error::other(format!(
371+
"add {syscall_name} operation failed with {errno}"
372+
)));
377373
}
378374
}
379375
eprintln!("add {syscall_name} operation:{overlapped}");
@@ -464,10 +460,9 @@ impl<'o> Operator<'o> {
464460
{
465461
let errno = WSAGetLastError();
466462
if WSA_IO_PENDING != errno {
467-
return Err(Error::new(
468-
ErrorKind::Other,
469-
format!("add {syscall_name} operation failed with {errno}"),
470-
));
463+
return Err(Error::other(format!(
464+
"add {syscall_name} operation failed with {errno}"
465+
)));
471466
}
472467
}
473468
eprintln!("add {syscall_name} operation:{overlapped}");

core/tests/coroutine.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ fn coroutine_panic() -> std::io::Result<()> {
2323
})?;
2424
match coroutine.resume()? {
2525
CoroutineState::Error(_) => Ok(()),
26-
_ => Err(std::io::Error::new(
27-
std::io::ErrorKind::Other,
28-
"The coroutine should panic",
29-
)),
26+
_ => Err(std::io::Error::other("The coroutine should panic")),
3027
}
3128
}
3229

@@ -233,8 +230,7 @@ fn coroutine_preemptive() -> std::io::Result<()> {
233230
)
234231
.unwrap();
235232
if result.1.timed_out() {
236-
Err(std::io::Error::new(
237-
std::io::ErrorKind::Other,
233+
Err(std::io::Error::other(
238234
"The monitor should send signals to coroutines in running state",
239235
))
240236
} else {
@@ -279,8 +275,7 @@ fn coroutine_syscall_not_preemptive() -> std::io::Result<()> {
279275
if result.1.timed_out() {
280276
Ok(())
281277
} else {
282-
Err(std::io::Error::new(
283-
std::io::ErrorKind::Other,
278+
Err(std::io::Error::other(
284279
"The monitor should not send signals to coroutines in syscall state",
285280
))
286281
}

hook/src/syscall/windows.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::ffi::{c_int, c_longlong, c_uint, c_void};
2-
use std::io::{Error, ErrorKind};
2+
use std::io::Error;
33
use windows_sys::core::{PCSTR, PCWSTR, PSTR};
44
use windows_sys::Win32::Foundation::{BOOL, HANDLE, TRUE};
55
use windows_sys::Win32::Networking::WinSock::{
@@ -89,6 +89,5 @@ unsafe fn attach() -> std::io::Result<()> {
8989
// impl_hook!("api-ms-win-core-synch-l1-2-0.dll", WAITONADDRESS, WaitOnAddress(address: *const c_void, compareaddress: *const c_void, addresssize: usize, dwmilliseconds: c_uint) -> BOOL);
9090

9191
// Enable the hook
92-
minhook::MinHook::enable_all_hooks()
93-
.map_err(|_| Error::new(ErrorKind::Other, "init all hooks failed !"))
92+
minhook::MinHook::enable_all_hooks().map_err(|_| Error::other("init all hooks failed !"))
9493
}

open-coroutine/examples/file_co.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,5 @@ pub fn main() -> Result<()> {
4242
if let Some(r) = join_handle.timeout_join(Duration::from_secs(30))? {
4343
return r;
4444
}
45-
Err(Error::new(
46-
std::io::ErrorKind::Other,
47-
"Failed to join the task",
48-
))
45+
Err(Error::other("Failed to join the task"))
4946
}

open-coroutine/examples/preemptive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ pub fn main() -> std::io::Result<()> {
7474
)
7575
.unwrap();
7676
if result.1.timed_out() {
77-
Err(std::io::Error::new(
78-
std::io::ErrorKind::Other,
77+
Err(std::io::Error::other(
7978
"preemptive schedule failed",
8079
))
8180
} else {

open-coroutine/examples/socket_co.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use open_coroutine::task;
2-
use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Read, Write};
2+
use std::io::{Error, IoSlice, IoSliceMut, Read, Write};
33
use std::net::{Shutdown, TcpListener, ToSocketAddrs};
44
#[cfg(unix)]
55
use std::os::fd::AsRawFd;
@@ -175,8 +175,7 @@ pub fn main() -> std::io::Result<()> {
175175
)
176176
.unwrap();
177177
if result.1.timed_out() {
178-
Err(Error::new(
179-
ErrorKind::Other,
178+
Err(Error::other(
180179
"The coroutine server and coroutine client did not completed within the specified time",
181180
))
182181
} else {

open-coroutine/examples/socket_co_client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use open_coroutine::task;
2-
use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Read, Write};
2+
use std::io::{Error, IoSlice, IoSliceMut, Read, Write};
33
use std::net::{Shutdown, TcpListener, ToSocketAddrs};
44
#[cfg(unix)]
55
use std::os::fd::AsRawFd;
@@ -170,8 +170,7 @@ pub fn main() -> std::io::Result<()> {
170170
)
171171
.unwrap();
172172
if result.1.timed_out() {
173-
Err(Error::new(
174-
ErrorKind::Other,
173+
Err(Error::other(
175174
"The coroutine client did not completed within the specified time",
176175
))
177176
} else {

open-coroutine/examples/socket_co_server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use open_coroutine::task;
2-
use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Read, Write};
2+
use std::io::{Error, IoSlice, IoSliceMut, Read, Write};
33
use std::net::{Shutdown, TcpListener, ToSocketAddrs};
44
#[cfg(unix)]
55
use std::os::fd::AsRawFd;
@@ -172,8 +172,7 @@ pub fn main() -> std::io::Result<()> {
172172
)
173173
.unwrap();
174174
if result.1.timed_out() {
175-
Err(Error::new(
176-
ErrorKind::Other,
175+
Err(Error::other(
177176
"The coroutine service did not completed within the specified time",
178177
))
179178
} else {

open-coroutine/examples/socket_not_co.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Read, Write};
1+
use std::io::{Error, IoSlice, IoSliceMut, Read, Write};
22
use std::net::{Shutdown, TcpListener, ToSocketAddrs};
33
#[cfg(unix)]
44
use std::os::fd::AsRawFd;
@@ -166,8 +166,7 @@ pub fn main() -> std::io::Result<()> {
166166
)
167167
.unwrap();
168168
if result.1.timed_out() {
169-
Err(Error::new(
170-
ErrorKind::Other,
169+
Err(Error::other(
171170
"The service did not completed within the specified time",
172171
))
173172
} else {

0 commit comments

Comments
 (0)