Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rex4539 committed Feb 1, 2025
1 parent b8ac94e commit 697283a
Show file tree
Hide file tree
Showing 42 changed files with 229 additions and 251 deletions.
2 changes: 1 addition & 1 deletion tokio-stream/src/stream_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ mod rand {
let s0 = self.two.get();

s1 ^= s1 << 17;
s1 = s1 ^ s0 ^ s1 >> 7 ^ s0 >> 16;
s1 = s1 ^ s0 ^ (s1 >> 7) ^ (s0 >> 16);

self.one.set(s0);
self.two.set(s1);
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where

struct ReadBufFn<'a, R, B>(&'a mut R, &'a mut B);

impl<'a, R, B> Future for ReadBufFn<'a, R, B>
impl<R, B> Future for ReadBufFn<'_, R, B>
where
R: AsyncRead + Unpin,
B: BufMut,
Expand Down
7 changes: 4 additions & 3 deletions tokio-util/src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! TCP/UDP/Unix helpers for tokio.
use crate::either::Either;
use std::future::Future;
use std::io::Result;
Expand All @@ -13,6 +12,7 @@ pub mod unix;
pub trait Listener {
/// The stream's type of this listener.
type Io: tokio::io::AsyncRead + tokio::io::AsyncWrite;

/// The socket address type of this listener.
type Addr;

Expand All @@ -39,8 +39,9 @@ impl Listener for tokio::net::TcpListener {
Self::poll_accept(self, cx)
}

// Fixed: Removed the redundant conversion
fn local_addr(&self) -> Result<Self::Addr> {
self.local_addr().map(Into::into)
self.local_addr()
}
}

Expand All @@ -51,7 +52,7 @@ pub struct ListenerAcceptFut<'a, L> {
listener: &'a mut L,
}

impl<'a, L> Future for ListenerAcceptFut<'a, L>
impl<L> Future for ListenerAcceptFut<'_, L>
where
L: Listener,
{
Expand Down
7 changes: 4 additions & 3 deletions tokio-util/src/net/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Unix domain socket helpers.
use super::Listener;
use std::io::Result;
use std::task::{Context, Poll};
Expand All @@ -9,10 +8,12 @@ impl Listener for tokio::net::UnixListener {
type Addr = tokio::net::unix::SocketAddr;

fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<Result<(Self::Io, Self::Addr)>> {
Self::poll_accept(self, cx)
// Call the concrete `poll_accept` method of `tokio::net::UnixListener`
<tokio::net::UnixListener>::poll_accept(self, cx)
}

fn local_addr(&self) -> Result<Self::Addr> {
self.local_addr().map(Into::into)
// Return the result of `local_addr` directly
self.local_addr()
}
}
6 changes: 3 additions & 3 deletions tokio-util/src/sync/cancellation_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl CancellationToken {
}
}

impl<'a, F: Future> Future for RunUntilCancelledFuture<'a, F> {
impl<F: Future> Future for RunUntilCancelledFuture<'_, F> {
type Output = Option<F::Output>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Expand All @@ -291,13 +291,13 @@ impl CancellationToken {

// ===== impl WaitForCancellationFuture =====

impl<'a> core::fmt::Debug for WaitForCancellationFuture<'a> {
impl core::fmt::Debug for WaitForCancellationFuture<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("WaitForCancellationFuture").finish()
}
}

impl<'a> Future for WaitForCancellationFuture<'a> {
impl Future for WaitForCancellationFuture<'_> {
type Output = ();

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
Expand Down
16 changes: 8 additions & 8 deletions tokio-util/src/sync/cancellation_token/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
//! Those invariants shall be true at any time.
//!
//! 1. A node that has no parents and no handles can no longer be cancelled.
//! This is important during both cancellation and refcounting.
//! This is important during both cancellation and refcounting.
//!
//! 2. If node B *is* or *was* a child of node A, then node B was created *after* node A.
//! This is important for deadlock safety, as it is used for lock order.
//! Node B can only become the child of node A in two ways:
//! - being created with `child_node()`, in which case it is trivially true that
//! node A already existed when node B was created
//! - being moved A->C->B to A->B because node C was removed in `decrease_handle_refcount()`
//! or `cancel()`. In this case the invariant still holds, as B was younger than C, and C
//! was younger than A, therefore B is also younger than A.
//! This is important for deadlock safety, as it is used for lock order.
//! Node B can only become the child of node A in two ways:
//! - being created with `child_node()`, in which case it is trivially true that
//! node A already existed when node B was created
//! - being moved A->C->B to A->B because node C was removed in `decrease_handle_refcount()`
//! or `cancel()`. In this case the invariant still holds, as B was younger than C, and C
//! was younger than A, therefore B is also younger than A.
//!
//! 3. If two nodes are both unlocked and node A is the parent of node B, then node B is a child of
//! node A. It is important to always restore that invariant before dropping the lock of a node.
Expand Down
4 changes: 2 additions & 2 deletions tokio-util/src/task/task_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl<F: fmt::Debug> fmt::Debug for TrackedFuture<F> {
}
}

impl<'a> Future for TaskTrackerWaitFuture<'a> {
impl Future for TaskTrackerWaitFuture<'_> {
type Output = ();

#[inline]
Expand All @@ -701,7 +701,7 @@ impl<'a> Future for TaskTrackerWaitFuture<'a> {
}
}

impl<'a> fmt::Debug for TaskTrackerWaitFuture<'a> {
impl fmt::Debug for TaskTrackerWaitFuture<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct Helper<'a>(&'a TaskTrackerInner);

Expand Down
23 changes: 3 additions & 20 deletions tokio-util/src/time/wheel/level.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::time::wheel::Stack;

use std::fmt;

/// Wheel for a single level in the timer. This wheel contains 64 slots.
pub(crate) struct Level<T> {
level: usize,

/// Bit field tracking which slots currently contain entries.
///
/// Using a bit field to track slots that contain entries allows avoiding a
Expand All @@ -14,7 +12,6 @@ pub(crate) struct Level<T> {
///
/// The least-significant bit represents slot zero.
occupied: u64,

/// Slots
slot: [T; LEVEL_MULT],
}
Expand All @@ -24,10 +21,8 @@ pub(crate) struct Level<T> {
pub(crate) struct Expiration {
/// The level containing the slot.
pub(crate) level: usize,

/// The slot index.
pub(crate) slot: usize,

/// The instant at which the slot needs to be processed.
pub(crate) deadline: u64,
}
Expand All @@ -51,20 +46,17 @@ impl<T: Stack> Level<T> {
pub(crate) fn next_expiration(&self, now: u64) -> Option<Expiration> {
// Use the `occupied` bit field to get the index of the next slot that
// needs to be processed.
let slot = match self.next_occupied_slot(now) {
Some(slot) => slot,
None => return None,
};
let slot = self.next_occupied_slot(now)?; // Replaced match with `?`

// From the slot index, calculate the `Instant` at which it needs to be
// processed. This value *must* be in the future with respect to `now`.

let level_range = level_range(self.level);
let slot_range = slot_range(self.level);

// TODO: This can probably be simplified w/ power of 2 math
let level_start = now - (now % level_range);
let mut deadline = level_start + slot as u64 * slot_range;

if deadline < now {
// A timer is in a slot "prior" to the current time. This can occur
// because we do not have an infinite hierarchy of timer levels, and
Expand All @@ -83,9 +75,9 @@ impl<T: Stack> Level<T> {
// compute a deadline before now, and it's the top level, it
// therefore means we're actually looking at a slot in the future.
debug_assert_eq!(self.level, super::NUM_LEVELS - 1);

deadline += level_range;
}

debug_assert!(
deadline >= now,
"deadline={:016X}; now={:016X}; level={}; slot={}; occupied={:b}",
Expand Down Expand Up @@ -113,41 +105,33 @@ impl<T: Stack> Level<T> {
let occupied = self.occupied.rotate_right(now_slot as u32);
let zeros = occupied.trailing_zeros() as usize;
let slot = (zeros + now_slot) % 64;

Some(slot)
}

pub(crate) fn add_entry(&mut self, when: u64, item: T::Owned, store: &mut T::Store) {
let slot = slot_for(when, self.level);

self.slot[slot].push(item, store);
self.occupied |= occupied_bit(slot);
}

pub(crate) fn remove_entry(&mut self, when: u64, item: &T::Borrowed, store: &mut T::Store) {
let slot = slot_for(when, self.level);

self.slot[slot].remove(item, store);

if self.slot[slot].is_empty() {
// The bit is currently set
debug_assert!(self.occupied & occupied_bit(slot) != 0);

// Unset the bit
self.occupied ^= occupied_bit(slot);
}
}

pub(crate) fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option<T::Owned> {
let ret = self.slot[slot].pop(store);

if ret.is_some() && self.slot[slot].is_empty() {
// The bit is currently set
debug_assert!(self.occupied & occupied_bit(slot) != 0);

self.occupied ^= occupied_bit(slot);
}

ret
}

Expand Down Expand Up @@ -190,7 +174,6 @@ mod test {
for pos in 0..64 {
assert_eq!(pos as usize, slot_for(pos, 0));
}

for level in 1..5 {
for pos in level..64 {
let a = pos * 64_usize.pow(level as u32);
Expand Down
10 changes: 5 additions & 5 deletions tokio-util/src/time/wheel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ where
///
/// # Arguments
///
/// * `when`: is the instant at which the entry should be fired. It is
/// represented as the number of milliseconds since the creation
/// of the timing wheel.
/// `when`: is the instant at which the entry should be fired. It is
/// represented as the number of milliseconds since the creation
/// of the timing wheel.
///
/// * `item`: The item to insert into the wheel.
/// `item`: The item to insert into the wheel.
///
/// * `store`: The slab or `()` when using heap storage.
/// `store`: The slab or `()` when using heap storage.
///
/// # Return
///
Expand Down
1 change: 0 additions & 1 deletion tokio/src/fs/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::path::Path;
/// # Ok(())
/// # }
/// ```
pub async fn copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<u64, std::io::Error> {
let from = from.as_ref().to_owned();
let to = to.as_ref().to_owned();
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/fs/create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::path::Path;
/// This function will return an error in the following situations, but is not
/// limited to just these cases:
///
/// * If any directory in the path specified by `path` does not already exist
/// If any directory in the path specified by `path` does not already exist
/// and it could not be created otherwise. The specific error conditions for
/// when a directory is being created (after it is determined to not exist) are
/// outlined by [`fs::create_dir`].
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/io/async_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ impl<'a, Inner: AsRawFd> AsyncFdReadyGuard<'a, Inner> {
}
}

impl<'a, Inner: AsRawFd> AsyncFdReadyMutGuard<'a, Inner> {
impl<Inner: AsRawFd> AsyncFdReadyMutGuard<'_, Inner> {
/// Indicates to tokio that the file descriptor is no longer ready. All
/// internal readiness flags will be cleared, and tokio will wait for the
/// next edge-triggered readiness notification from the OS.
Expand Down Expand Up @@ -1369,15 +1369,15 @@ impl<'a, Inner: AsRawFd> AsyncFdReadyMutGuard<'a, Inner> {
}
}

impl<'a, T: std::fmt::Debug + AsRawFd> std::fmt::Debug for AsyncFdReadyGuard<'a, T> {
impl<T: std::fmt::Debug + AsRawFd> std::fmt::Debug for AsyncFdReadyGuard<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ReadyGuard")
.field("async_fd", &self.async_fd)
.finish()
}
}

impl<'a, T: std::fmt::Debug + AsRawFd> std::fmt::Debug for AsyncFdReadyMutGuard<'a, T> {
impl<T: std::fmt::Debug + AsRawFd> std::fmt::Debug for AsyncFdReadyMutGuard<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MutReadyGuard")
.field("async_fd", &self.async_fd)
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<'a> ReadBuf<'a> {

#[cfg(feature = "io-util")]
#[cfg_attr(docsrs, doc(cfg(feature = "io-util")))]
unsafe impl<'a> bytes::BufMut for ReadBuf<'a> {
unsafe impl bytes::BufMut for ReadBuf<'_> {
fn remaining_mut(&self) -> usize {
self.remaining()
}
Expand Down
16 changes: 8 additions & 8 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,26 @@
//!
//! - `full`: Enables all features listed below except `test-util` and `tracing`.
//! - `rt`: Enables `tokio::spawn`, the current-thread scheduler,
//! and non-scheduler utilities.
//! and non-scheduler utilities.
//! - `rt-multi-thread`: Enables the heavier, multi-threaded, work-stealing scheduler.
//! - `io-util`: Enables the IO based `Ext` traits.
//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and
//! `UdpSocket`, as well as (on Unix-like systems) `AsyncFd` and (on
//! FreeBSD) `PollAio`.
//! `UdpSocket`, as well as (on Unix-like systems) `AsyncFd` and (on
//! FreeBSD) `PollAio`.
//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
//! the built in timer.
//! the built in timer.
//! - `process`: Enables `tokio::process` types.
//! - `macros`: Enables `#[tokio::main]` and `#[tokio::test]` macros.
//! - `sync`: Enables all `tokio::sync` types.
//! - `signal`: Enables all `tokio::signal` types.
//! - `fs`: Enables `tokio::fs` types.
//! - `test-util`: Enables testing based infrastructure for the Tokio runtime.
//! - `parking_lot`: As a potential optimization, use the `_parking_lot_` crate's
//! synchronization primitives internally. Also, this
//! dependency is necessary to construct some of our primitives
//! in a `const` context. `MSRV` may increase according to the
//! `_parking_lot_` release in use.
//! synchronization primitives internally. Also, this
//! dependency is necessary to construct some of our primitives
//! in a `const` context. `MSRV` may increase according to the
//! `_parking_lot_` release in use.
//!
//! _Note: `AsyncRead` and `AsyncWrite` traits do not require any features and are
//! always available._
Expand Down
Loading

0 comments on commit 697283a

Please sign in to comment.