From e80f3cdf89d13ff846048448b97afbe767a89319 Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Wed, 5 Feb 2025 17:10:37 +0200 Subject: [PATCH] allow clippy::needless_lifetimes --- .github/workflows/ci.yml | 2 +- tokio-util/src/lib.rs | 1 + tokio-util/src/net/mod.rs | 1 - tokio-util/src/time/wheel/level.rs | 2 +- tokio-util/src/time/wheel/mod.rs | 10 +++++----- tokio/src/lib.rs | 1 + tokio/src/net/mod.rs | 16 ++++++++-------- tokio/src/sync/semaphore.rs | 2 +- tokio/src/task/join_set.rs | 30 +++++++++++++++--------------- tokio/tests/io_join.rs | 6 +++--- tokio/tests/io_split.rs | 2 +- tokio/tests/support/io_vec.rs | 2 +- tokio/tests/tcp_accept.rs | 2 +- 13 files changed, 39 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 813d0e18a35..75880383076 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: 'nightly-2025-01-25' + rust_clippy: '1.84.1' # When updating this, also update: # - README.md # - tokio/README.md diff --git a/tokio-util/src/lib.rs b/tokio-util/src/lib.rs index 1df4de1b459..8509f5c251b 100644 --- a/tokio-util/src/lib.rs +++ b/tokio-util/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::needless_lifetimes)] #![allow(clippy::needless_doctest_main)] #![warn( missing_debug_implementations, diff --git a/tokio-util/src/net/mod.rs b/tokio-util/src/net/mod.rs index 30a4fea0da0..3b829b9df7c 100644 --- a/tokio-util/src/net/mod.rs +++ b/tokio-util/src/net/mod.rs @@ -39,7 +39,6 @@ impl Listener for tokio::net::TcpListener { Self::poll_accept(self, cx) } - // Fixed: Removed the redundant conversion fn local_addr(&self) -> Result { self.local_addr() } diff --git a/tokio-util/src/time/wheel/level.rs b/tokio-util/src/time/wheel/level.rs index 4d0f314cd47..4025d2a12fd 100644 --- a/tokio-util/src/time/wheel/level.rs +++ b/tokio-util/src/time/wheel/level.rs @@ -46,7 +46,7 @@ impl Level { pub(crate) fn next_expiration(&self, now: u64) -> Option { // Use the `occupied` bit field to get the index of the next slot that // needs to be processed. - let slot = self.next_occupied_slot(now)?; // Replaced match with `?` + let slot = self.next_occupied_slot(now)?; // 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`. diff --git a/tokio-util/src/time/wheel/mod.rs b/tokio-util/src/time/wheel/mod.rs index 1accd32f4ab..55254690961 100644 --- a/tokio-util/src/time/wheel/mod.rs +++ b/tokio-util/src/time/wheel/mod.rs @@ -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 /// diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index b3522390959..ef66d8c08a1 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -1,4 +1,5 @@ #![allow( + clippy::needless_lifetimes, clippy::cognitive_complexity, clippy::large_enum_variant, clippy::module_inception, diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs index 5db4ec80534..bf8b252511c 100644 --- a/tokio/src/net/mod.rs +++ b/tokio/src/net/mod.rs @@ -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 -//! Unix Domain Stream Socket **(available on Unix only)** -//! [`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)** +//! [`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 +//! 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)** //! //! For IO resources not available in `tokio::net`, you can use [`AsyncFd`]. //! diff --git a/tokio/src/sync/semaphore.rs b/tokio/src/sync/semaphore.rs index 9d817c0b71d..97963afddc2 100644 --- a/tokio/src/sync/semaphore.rs +++ b/tokio/src/sync/semaphore.rs @@ -964,7 +964,7 @@ impl Semaphore { } } -impl SemaphorePermit<'_> { +impl<'a> SemaphorePermit<'a> { /// Forgets the permit **without** releasing it back to the semaphore. /// This can be used to reduce the amount of permits available from a /// semaphore. diff --git a/tokio/src/task/join_set.rs b/tokio/src/task/join_set.rs index 96f401b9760..08f8a6d9da6 100644 --- a/tokio/src/task/join_set.rs +++ b/tokio/src/task/join_set.rs @@ -471,13 +471,13 @@ impl JoinSet { /// /// 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. @@ -525,14 +525,14 @@ impl JoinSet { /// /// 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. diff --git a/tokio/tests/io_join.rs b/tokio/tests/io_join.rs index 69b09393311..2554bfd0773 100644 --- a/tokio/tests/io_join.rs +++ b/tokio/tests/io_join.rs @@ -15,7 +15,7 @@ impl AsyncRead for R { _cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - buf.put_slice(&[b'z']); + buf.put_slice(&[b'z'][..]); Poll::Ready(Ok(())) } } @@ -68,10 +68,10 @@ fn method_delegation() { assert_eq!(1, rw.read(&mut buf).await.unwrap()); assert_eq!(b'z', buf[0]); - assert_eq!(1, rw.write(&[b'x']).await.unwrap()); + assert_eq!(1, rw.write(&[b'x'][..]).await.unwrap()); assert_eq!( 2, - rw.write_vectored(&[io::IoSlice::new(&[b'x'])]) + rw.write_vectored(&[io::IoSlice::new(&[b'x'][..])]).await.unwrap(); .await .unwrap() ); diff --git a/tokio/tests/io_split.rs b/tokio/tests/io_split.rs index 9f17c9eb14e..348d028a23f 100644 --- a/tokio/tests/io_split.rs +++ b/tokio/tests/io_split.rs @@ -104,7 +104,7 @@ fn method_delegation() { assert_eq!(1, w.write(&[b'x']).await.unwrap()); assert_eq!( 2, - w.write_vectored(&[io::IoSlice::new(&[b'x'])]) + w.write_vectored(&[io::IoSlice::new(&[b"x"])]) .await .unwrap() ); diff --git a/tokio/tests/support/io_vec.rs b/tokio/tests/support/io_vec.rs index 4ea47c748d1..9da06bf44e1 100644 --- a/tokio/tests/support/io_vec.rs +++ b/tokio/tests/support/io_vec.rs @@ -37,7 +37,7 @@ impl<'a, 'b> IoBufs<'a, 'b> { } } -impl<'a, 'b> Deref for IoBufs<'a, 'b> { +impl<'a> Deref for IoBufs<'a, '_> { type Target = [IoSlice<'a>]; fn deref(&self) -> &[IoSlice<'a>] { self.0 diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs index 766304778df..8c2984294aa 100644 --- a/tokio/tests/tcp_accept.rs +++ b/tokio/tests/tcp_accept.rs @@ -54,7 +54,7 @@ struct TrackPolls<'a> { listener: &'a mut TcpListener, } -impl<'a> Stream for TrackPolls<'a> { +impl Stream for TrackPolls<'_> { type Item = io::Result<(TcpStream, SocketAddr)>; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> {