From c003ae9700011087c96822df84a37ade414decad Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Sat, 25 May 2024 12:37:55 +0800 Subject: [PATCH] refactor: fix clippy & unused imports/helper type (#2416) --- src/lib.rs | 2 +- src/sched.rs | 5 ++++- src/sys/socket/sockopt.rs | 24 +++++++++++++++++++++--- src/sys/timer.rs | 2 +- src/sys/timerfd.rs | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c4c0fa53cc..476ea241a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,7 +205,7 @@ pub type Result = result::Result; /// * `Eq` /// * Small size /// * Represents all of the system's errnos, instead of just the most common -/// ones. +/// ones. pub type Error = Errno; /// Common trait used to represent file system paths by many Nix functions. diff --git a/src/sched.rs b/src/sched.rs index d76d5581d1..617d00493f 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -120,7 +120,10 @@ mod sched_linux_like { let ptr = stack.as_mut_ptr().add(stack.len()); let ptr_aligned = ptr.sub(ptr as usize % 16); libc::clone( - mem::transmute( + mem::transmute::< + extern "C" fn(*mut Box isize>) -> i32, + extern "C" fn(*mut libc::c_void) -> i32, + >( callback as extern "C" fn(*mut Box isize>) -> i32, ), diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index f66b54e1fa..810340041d 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -5,8 +5,12 @@ use crate::sys::time::TimeVal; use crate::Result; use cfg_if::cfg_if; use libc::{self, c_int, c_void, socklen_t}; -use std::ffi::{CStr, CString, OsStr, OsString}; +#[cfg(apple_targets)] +use std::ffi::{CStr, CString}; +#[cfg(any(target_os = "freebsd", linux_android))] +use std::ffi::{OsStr, OsString}; use std::mem::{self, MaybeUninit}; +#[cfg(any(target_os = "freebsd", linux_android))] use std::os::unix::ffi::OsStrExt; use std::os::unix::io::{AsFd, AsRawFd}; @@ -749,7 +753,12 @@ sockopt_impl!( libc::SO_TIMESTAMPING, super::TimestampingFlag ); -#[cfg(not(any(target_os = "aix", target_os = "haiku", target_os = "hurd", target_os = "redox")))] +#[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "hurd", + target_os = "redox" +)))] sockopt_impl!( /// Enable or disable the receiving of the `SO_TIMESTAMP` control message. ReceiveTimestamp, @@ -1300,7 +1309,6 @@ impl SetSockOpt for TcpTlsRx { } } - /* * * ===== Accessor helpers ===== @@ -1438,11 +1446,13 @@ impl<'a> Set<'a, bool> for SetBool { } /// Getter for an `u8` value. +#[cfg(feature = "net")] struct GetU8 { len: socklen_t, val: MaybeUninit, } +#[cfg(feature = "net")] impl Get for GetU8 { fn uninit() -> Self { GetU8 { @@ -1470,10 +1480,12 @@ impl Get for GetU8 { } /// Setter for an `u8` value. +#[cfg(feature = "net")] struct SetU8 { val: u8, } +#[cfg(feature = "net")] impl<'a> Set<'a, u8> for SetU8 { fn new(val: &'a u8) -> SetU8 { SetU8 { val: *val } @@ -1540,11 +1552,13 @@ impl<'a> Set<'a, usize> for SetUsize { } /// Getter for a `OsString` value. +#[cfg(any(target_os = "freebsd", linux_android))] struct GetOsString> { len: socklen_t, val: MaybeUninit, } +#[cfg(any(target_os = "freebsd", linux_android))] impl> Get for GetOsString { fn uninit() -> Self { GetOsString { @@ -1569,10 +1583,12 @@ impl> Get for GetOsString { } /// Setter for a `OsString` value. +#[cfg(any(target_os = "freebsd", linux_android))] struct SetOsString<'a> { val: &'a OsStr, } +#[cfg(any(target_os = "freebsd", linux_android))] impl<'a> Set<'a, OsString> for SetOsString<'a> { fn new(val: &'a OsString) -> SetOsString { SetOsString { @@ -1590,11 +1606,13 @@ impl<'a> Set<'a, OsString> for SetOsString<'a> { } /// Getter for a `CString` value. +#[cfg(apple_targets)] struct GetCString> { len: socklen_t, val: MaybeUninit, } +#[cfg(apple_targets)] impl> Get for GetCString { fn uninit() -> Self { GetCString { diff --git a/src/sys/timer.rs b/src/sys/timer.rs index e1a34051e8..8876f56972 100644 --- a/src/sys/timer.rs +++ b/src/sys/timer.rs @@ -95,7 +95,7 @@ impl Timer { /// There are 3 types of alarms you can set: /// /// - one shot: the alarm will trigger once after the specified amount of - /// time. + /// time. /// Example: I want an alarm to go off in 60s and then disable itself. /// /// - interval: the alarm will trigger every specified interval of time. diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs index 68b06d6322..6a13c843e8 100644 --- a/src/sys/timerfd.rs +++ b/src/sys/timerfd.rs @@ -113,7 +113,7 @@ impl TimerFd { /// There are 3 types of alarms you can set: /// /// - one shot: the alarm will trigger once after the specified amount of - /// time. + /// time. /// Example: I want an alarm to go off in 60s and then disable itself. /// /// - interval: the alarm will trigger every specified interval of time.