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 5, 2025
1 parent b8ac94e commit 3277912
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
rust_nightly: nightly-2025-01-25
# Pin a specific miri version
rust_miri_nightly: nightly-2025-01-25
rust_clippy: '1.77'
rust_clippy: 'nightly-2025-01-25'
# When updating this, also update:
# - README.md
# - tokio/README.md
Expand Down
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
5 changes: 3 additions & 2 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 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()
}
}
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
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
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
12 changes: 6 additions & 6 deletions tokio/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
//!
//! # Organization
//!
//! * [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP
//! * [`UdpSocket`] provides functionality for communication over UDP
//! * [`UnixListener`] and [`UnixStream`] provide functionality for communication over a
//! [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP
//! [`UdpSocket`] provides functionality for communication over UDP
//! [`UnixListener`] and [`UnixStream`] provide functionality for communication over a
//! Unix Domain Stream Socket **(available on Unix only)**
//! * [`UnixDatagram`] provides functionality for communication
//! [`UnixDatagram`] provides functionality for communication
//! over Unix Domain Datagram Socket **(available on Unix only)**
//! * [`tokio::net::unix::pipe`] for FIFO pipes **(available on Unix only)**
//! * [`tokio::net::windows::named_pipe`] for Named Pipes **(available on Windows only)**
//! [`tokio::net::unix::pipe`] for FIFO pipes **(available on Unix only)**
//! [`tokio::net::windows::named_pipe`] for Named Pipes **(available on Windows only)**
//!
//! For IO resources not available in `tokio::net`, you can use [`AsyncFd`].
//!
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/io/scheduled_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl ScheduledIo {
///
/// # Arguments
/// - `tick`: whether setting the tick or trying to clear readiness for a
/// specific tick.
/// specific tick.
/// - `f`: a closure returning a new readiness value given the previous
/// readiness.
pub(super) fn set_readiness(&self, tick_op: Tick, f: impl Fn(Ready) -> Ready) {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/time/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl TimerEntry {
*self.inner.get() = Some(TimerShared::new(shard_id));
}
}
return inner.as_ref().unwrap();
inner.as_ref().unwrap()
}

pub(crate) fn deadline(&self) -> Instant {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ impl<T> From<T> for RwLock<T> {
}
}

impl<T: ?Sized> Default for RwLock<T>
impl<T> Default for RwLock<T>
where
T: Default,
{
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/sync/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ impl Semaphore {
}
}

impl<'a> SemaphorePermit<'a> {
impl SemaphorePermit<'_> {
/// Forgets the permit **without** releasing it back to the semaphore.
/// This can be used to reduce the amount of permits available from a
/// semaphore.
Expand Down
30 changes: 15 additions & 15 deletions tokio/src/task/join_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,13 @@ impl<T: 'static> JoinSet<T> {
///
/// This function returns:
///
/// * `Poll::Pending` if the `JoinSet` is not empty but there is no task whose output is
/// available right now.
/// * `Poll::Ready(Some(Ok(value)))` if one of the tasks in this `JoinSet` has completed.
/// The `value` is the return value of one of the tasks that completed.
/// * `Poll::Ready(Some(Err(err)))` if one of the tasks in this `JoinSet` has panicked or been
/// aborted. The `err` is the `JoinError` from the panicked/aborted task.
/// * `Poll::Ready(None)` if the `JoinSet` is empty.
/// `Poll::Pending` if the `JoinSet` is not empty but there is no task whose output is
/// available right now.
/// `Poll::Ready(Some(Ok(value)))` if one of the tasks in this `JoinSet` has completed.
/// The `value` is the return value of one of the tasks that completed.
/// `Poll::Ready(Some(Err(err)))` if one of the tasks in this `JoinSet` has panicked or been
/// aborted. The `err` is the `JoinError` from the panicked/aborted task.
/// `Poll::Ready(None)` if the `JoinSet` is empty.
///
/// Note that this method may return `Poll::Pending` even if one of the tasks has completed.
/// This can happen if the [coop budget] is reached.
Expand Down Expand Up @@ -525,14 +525,14 @@ impl<T: 'static> JoinSet<T> {
///
/// This function returns:
///
/// * `Poll::Pending` if the `JoinSet` is not empty but there is no task whose output is
/// available right now.
/// * `Poll::Ready(Some(Ok((id, value))))` if one of the tasks in this `JoinSet` has completed.
/// The `value` is the return value of one of the tasks that completed, and
/// `id` is the [task ID] of that task.
/// * `Poll::Ready(Some(Err(err)))` if one of the tasks in this `JoinSet` has panicked or been
/// aborted. The `err` is the `JoinError` from the panicked/aborted task.
/// * `Poll::Ready(None)` if the `JoinSet` is empty.
/// `Poll::Pending` if the `JoinSet` is not empty but there is no task whose output is
/// available right now.
/// `Poll::Ready(Some(Ok((id, value))))` if one of the tasks in this `JoinSet` has completed.
/// The `value` is the return value of one of the tasks that completed, and
/// `id` is the [task ID] of that task.
/// `Poll::Ready(Some(Err(err)))` if one of the tasks in this `JoinSet` has panicked or been
/// aborted. The `err` is the `JoinError` from the panicked/aborted task.
/// `Poll::Ready(None)` if the `JoinSet` is empty.
///
/// Note that this method may return `Poll::Pending` even if one of the tasks has completed.
/// This can happen if the [coop budget] is reached.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/util/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl FastRand {
let s0 = self.two;

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

self.one = s0;
self.two = s1;
Expand Down

0 comments on commit 3277912

Please sign in to comment.