Skip to content

Commit

Permalink
📝 fix cargo clippy for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Xudong-Huang committed Oct 7, 2024
1 parent 3afb2d3 commit 8c89bf3
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 72 deletions.
18 changes: 9 additions & 9 deletions src/coroutine_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::scheduler::get_scheduler;
use crate::sync::AtomicOption;
use generator::{Generator, Gn};

/// /////////////////////////////////////////////////////////////////////////////
/// Coroutine framework types
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Coroutine framework types
////////////////////////////////////////////////////////////////////////////////

pub type EventResult = io::Error;

Expand Down Expand Up @@ -48,9 +48,9 @@ pub trait EventSource {
}
}

/// /////////////////////////////////////////////////////////////////////////////
/// Coroutine destruction
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Coroutine destruction
////////////////////////////////////////////////////////////////////////////////

pub struct Done;

Expand Down Expand Up @@ -95,9 +95,9 @@ fn get_co_local(co: &CoroutineImpl) -> *mut CoroutineLocal {
co.get_local_data() as *mut CoroutineLocal
}

/// /////////////////////////////////////////////////////////////////////////////
/// Coroutine
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Coroutine
////////////////////////////////////////////////////////////////////////////////

/// The internal representation of a `Coroutine` handle
struct Inner {
Expand Down
8 changes: 4 additions & 4 deletions src/cqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub struct EventSender<'a> {
cqueue: &'a Cqueue,
}

unsafe impl<'a> Send for EventSender<'a> {}
unsafe impl Send for EventSender<'_> {}

impl<'a> EventSender<'a> {
impl EventSender<'_> {
/// get the token
pub fn get_token(&self) -> usize {
self.token
Expand All @@ -111,7 +111,7 @@ impl<'a> EventSender<'a> {
}
}

impl<'a> EventSource for EventSender<'a> {
impl EventSource for EventSender<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
self.cqueue.ev_queue.push(Event {
id: self.id,
Expand All @@ -130,7 +130,7 @@ impl<'a> EventSource for EventSender<'a> {
}
}

impl<'a> Drop for EventSender<'a> {
impl Drop for EventSender<'_> {
// when the select coroutine finished will trigger this drop
fn drop(&mut self) {
self.cqueue.ev_queue.push(Event {
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/miow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub struct AcceptAddrs<'a> {
_data: &'a AcceptAddrsBuf,
}

impl<'a> AcceptAddrs<'a> {
impl AcceptAddrs<'_> {
/// Returns the local socket address contained in this buffer.
#[allow(dead_code)]
pub fn local(&self) -> Option<SocketAddr> {
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/socket_peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> SocketPeek<'a> {
}
}

impl<'a> EventSource for SocketPeek<'a> {
impl EventSource for SocketPeek<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
#[cfg(feature = "io_cancel")]
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/socket_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> SocketRead<'a> {
}
}

impl<'a> EventSource for SocketRead<'a> {
impl EventSource for SocketRead<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
#[cfg(feature = "io_cancel")]
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/socket_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> SocketWrite<'a> {
}
}

impl<'a> EventSource for SocketWrite<'a> {
impl EventSource for SocketWrite<'_> {
#[allow(clippy::needless_return)]
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/tcp_listener_accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'a> TcpListenerAccept<'a> {
}
}

impl<'a> EventSource for TcpListenerAccept<'a> {
impl EventSource for TcpListenerAccept<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
let _g = self.can_drop.delay_drop();
let s = get_scheduler();
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/udp_recv_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a> UdpRecvFrom<'a> {
}
}

impl<'a> EventSource for UdpRecvFrom<'a> {
impl EventSource for UdpRecvFrom<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
let _g = self.can_drop.delay_drop();
let s = get_scheduler();
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/net/udp_send_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a> UdpSendTo<'a> {
}
}

impl<'a> EventSource for UdpSendTo<'a> {
impl EventSource for UdpSendTo<'_> {
#[allow(clippy::needless_return)]
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/pipe/pipe_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> PipeRead<'a> {
}
}

impl<'a> EventSource for PipeRead<'a> {
impl EventSource for PipeRead<'_> {
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
#[cfg(feature = "io_cancel")]
Expand Down
2 changes: 1 addition & 1 deletion src/io/sys/windows/pipe/pipe_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a> PipeWrite<'a> {
}
}

impl<'a> EventSource for PipeWrite<'a> {
impl EventSource for PipeWrite<'_> {
#[allow(clippy::needless_return)]
fn subscribe(&mut self, co: CoroutineImpl) {
let s = get_scheduler();
Expand Down
2 changes: 1 addition & 1 deletion src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ pub struct Incoming<'a> {
listener: &'a TcpListener,
}

impl<'a> Iterator for Incoming<'a> {
impl Iterator for Incoming<'_> {
type Item = io::Result<TcpStream>;
fn next(&mut self) -> Option<io::Result<TcpStream>> {
Some(self.listener.accept().map(|p| p.0))
Expand Down
2 changes: 1 addition & 1 deletion src/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Park {
}
}

impl<'a> Drop for DropGuard<'a> {
impl Drop for DropGuard<'_> {
fn drop(&mut self) {
self.0.wait_kernel.store(false, Ordering::Release);
}
Expand Down
4 changes: 2 additions & 2 deletions src/scoped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where
ret
}

impl<'a> fmt::Debug for Scope<'a> {
impl fmt::Debug for Scope<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Scope {{ ... }}")
}
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<T> ScopedJoinHandle<T> {
}
}

impl<'a> Drop for Scope<'a> {
impl Drop for Scope<'_> {
fn drop(&mut self) {
self.drop_all()
}
Expand Down
7 changes: 1 addition & 6 deletions src/sync/atomic_dur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,5 @@ impl AtomicDuration {
}

fn dur_to_ms(dur: Duration) -> u64 {
// Note that a duration is a (u64, u32) (seconds, nanoseconds) pair
const MS_PER_SEC: u64 = 1_000;
const NANOS_PER_MILLI: u64 = 1_000_000;
let ns = u64::from(dur.subsec_nanos());
let ms = (ns + NANOS_PER_MILLI - 1) / NANOS_PER_MILLI;
dur.as_secs().saturating_mul(MS_PER_SEC).saturating_add(ms)
dur.as_millis() as u64
}
2 changes: 1 addition & 1 deletion src/sync/delay_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl DelayDrop {
}
}

impl<'a> Drop for DropGuard<'a> {
impl Drop for DropGuard<'_> {
fn drop(&mut self) {
// kernel would set it to true
self.0.can_drop.fetch_and(1, Ordering::Release);
Expand Down
16 changes: 8 additions & 8 deletions src/sync/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
(Sender::new(a.clone()), Receiver::new(a))
}

/// /////////////////////////////////////////////////////////////////////////////
/// Sender
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Sender
////////////////////////////////////////////////////////////////////////////////

impl<T> Sender<T> {
fn new(inner: Arc<InnerQueue<T>>) -> Sender<T> {
Expand Down Expand Up @@ -200,9 +200,9 @@ impl<T> fmt::Debug for Sender<T> {
}
}

/// /////////////////////////////////////////////////////////////////////////////
/// Receiver
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Receiver
////////////////////////////////////////////////////////////////////////////////

impl<T> Receiver<T> {
fn new(inner: Arc<InnerQueue<T>>) -> Receiver<T> {
Expand Down Expand Up @@ -233,15 +233,15 @@ impl<T> Receiver<T> {
}
}

impl<'a, T> Iterator for Iter<'a, T> {
impl<T> Iterator for Iter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
self.rx.recv().ok()
}
}

impl<'a, T> Iterator for TryIter<'a, T> {
impl<T> Iterator for TryIter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
Expand Down
16 changes: 8 additions & 8 deletions src/sync/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
(Sender::new(a.clone()), Receiver::new(a))
}

/// /////////////////////////////////////////////////////////////////////////////
/// Sender
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Sender
////////////////////////////////////////////////////////////////////////////////

impl<T> Sender<T> {
fn new(inner: Arc<InnerQueue<T>>) -> Sender<T> {
Expand Down Expand Up @@ -179,9 +179,9 @@ impl<T> fmt::Debug for Sender<T> {
}
}

/// /////////////////////////////////////////////////////////////////////////////
/// Receiver
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Receiver
////////////////////////////////////////////////////////////////////////////////

impl<T> Receiver<T> {
fn new(inner: Arc<InnerQueue<T>>) -> Receiver<T> {
Expand Down Expand Up @@ -237,15 +237,15 @@ impl<T> Receiver<T> {
}
}

impl<'a, T> Iterator for Iter<'a, T> {
impl<T> Iterator for Iter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
self.rx.recv().ok()
}
}

impl<'a, T> Iterator for TryIter<'a, T> {
impl<T> Iterator for TryIter<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
Expand Down
8 changes: 4 additions & 4 deletions src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,21 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
}
}

impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> {
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { &*self.__lock.data.get() }
}
}

impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> {
impl<T: ?Sized> DerefMut for MutexGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.__lock.data.get() }
}
}

impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
impl<T: ?Sized> Drop for MutexGuard<'_, T> {
#[inline]
fn drop(&mut self) {
self.__lock.poison.done(&self.__poison);
Expand All @@ -214,7 +214,7 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> {
}
}

impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
impl<T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("MutexGuard")
.field("lock", &self.__lock)
Expand Down
14 changes: 7 additions & 7 deletions src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,51 +265,51 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> {
}
}

impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> {
impl<T: fmt::Debug> fmt::Debug for RwLockReadGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RwLockReadGuard")
.field("lock", &self.__lock)
.finish()
}
}

impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> {
impl<T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RwLockWriteGuard")
.field("lock", &self.__lock)
.finish()
}
}

impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> {
impl<T: ?Sized> Deref for RwLockReadGuard<'_, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { &*self.__lock.data.get() }
}
}

impl<'rwlock, T: ?Sized> Deref for RwLockWriteGuard<'rwlock, T> {
impl<T: ?Sized> Deref for RwLockWriteGuard<'_, T> {
type Target = T;

fn deref(&self) -> &T {
unsafe { &*self.__lock.data.get() }
}
}

impl<'rwlock, T: ?Sized> DerefMut for RwLockWriteGuard<'rwlock, T> {
impl<T: ?Sized> DerefMut for RwLockWriteGuard<'_, T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.__lock.data.get() }
}
}

impl<'a, T: ?Sized> Drop for RwLockReadGuard<'a, T> {
impl<T: ?Sized> Drop for RwLockReadGuard<'_, T> {
fn drop(&mut self) {
self.__lock.read_unlock();
}
}

impl<'a, T: ?Sized> Drop for RwLockWriteGuard<'a, T> {
impl<T: ?Sized> Drop for RwLockWriteGuard<'_, T> {
fn drop(&mut self) {
self.__lock.poison.done(&self.__poison);
self.__lock.write_unlock();
Expand Down
Loading

0 comments on commit 8c89bf3

Please sign in to comment.