From d0ce8ae90a86c29bfec39e0894dcbc18375faf7b Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Sat, 17 Aug 2024 16:37:31 +0200 Subject: [PATCH] lint: assortment of clippy lints --- examples/tinyhttp.rs | 4 ++-- tokio-util/tests/sync_cancellation_token.rs | 2 +- tokio/src/fs/create_dir_all.rs | 6 +++--- tokio/src/fs/mocks.rs | 3 ++- tokio/src/net/mod.rs | 4 ++-- tokio/src/process/unix/pidfd_reaper.rs | 2 +- tokio/src/sync/rwlock.rs | 2 +- tokio/src/time/clock.rs | 10 +++++----- tokio/tests/io_join.rs | 8 +++----- tokio/tests/io_panic.rs | 2 +- tokio/tests/io_split.rs | 8 +++----- tokio/tests/time_interval.rs | 2 +- tokio/tests/udp.rs | 8 ++++---- 13 files changed, 29 insertions(+), 32 deletions(-) diff --git a/examples/tinyhttp.rs b/examples/tinyhttp.rs index 38fce4f1a91..66a242af42e 100644 --- a/examples/tinyhttp.rs +++ b/examples/tinyhttp.rs @@ -212,10 +212,10 @@ impl Decoder for Http { ret = ret.header(&data[k.0..k.1], value); } - let req = ret + let request = ret .body(()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; - Ok(Some(req)) + Ok(Some(request)) } } diff --git a/tokio-util/tests/sync_cancellation_token.rs b/tokio-util/tests/sync_cancellation_token.rs index db33114a2e3..82cb28660ae 100644 --- a/tokio-util/tests/sync_cancellation_token.rs +++ b/tokio-util/tests/sync_cancellation_token.rs @@ -234,7 +234,7 @@ fn cancel_child_token_without_parent() { #[test] fn create_child_token_after_parent_was_cancelled() { - for drop_child_first in [true, false].iter().cloned() { + for drop_child_first in [true, false].iter().copied() { let (waker, wake_counter) = new_count_waker(); let token = CancellationToken::new(); token.cancel(); diff --git a/tokio/src/fs/create_dir_all.rs b/tokio/src/fs/create_dir_all.rs index 0a85b6a0c7f..1256469b500 100644 --- a/tokio/src/fs/create_dir_all.rs +++ b/tokio/src/fs/create_dir_all.rs @@ -22,9 +22,9 @@ use std::path::Path; /// limited to just these cases: /// /// * 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`]. +/// 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`]. /// /// Notable exception is made for situations where any of the directories /// specified in the `path` could not be created as it was being created concurrently. diff --git a/tokio/src/fs/mocks.rs b/tokio/src/fs/mocks.rs index 54da6be938c..80317c5eff5 100644 --- a/tokio/src/fs/mocks.rs +++ b/tokio/src/fs/mocks.rs @@ -1,4 +1,5 @@ -//! Mock version of std::fs::File; +//! Mock version of [`std::fs::File`]. + use mockall::mock; use crate::sync::oneshot; diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs index d5562ac5d47..1a19a47b277 100644 --- a/tokio/src/net/mod.rs +++ b/tokio/src/net/mod.rs @@ -10,9 +10,9 @@ //! * [`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)** +//! Unix Domain Stream Socket **(available on Unix only)** //! * [`UnixDatagram`] provides functionality for communication -//! over Unix Domain Datagram Socket **(available on Unix only)** +//! 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)** //! diff --git a/tokio/src/process/unix/pidfd_reaper.rs b/tokio/src/process/unix/pidfd_reaper.rs index c37b55e703a..f79739a2141 100644 --- a/tokio/src/process/unix/pidfd_reaper.rs +++ b/tokio/src/process/unix/pidfd_reaper.rs @@ -162,7 +162,7 @@ where if let Some(pidfd) = Pidfd::open(inner.id()) { match PollEvented::new_with_interest(pidfd, Interest::READABLE) { Ok(pidfd) => Ok(Self { - inner: Some(PidfdReaperInner { pidfd, inner }), + inner: Some(PidfdReaperInner { inner, pidfd }), orphan_queue, }), Err(io_error) => Err((Some(io_error), inner)), diff --git a/tokio/src/sync/rwlock.rs b/tokio/src/sync/rwlock.rs index eaeb994a53c..4f111cd6298 100644 --- a/tokio/src/sync/rwlock.rs +++ b/tokio/src/sync/rwlock.rs @@ -1094,7 +1094,7 @@ impl From for RwLock { } } -impl Default for RwLock +impl Default for RwLock where T: Default, { diff --git a/tokio/src/time/clock.rs b/tokio/src/time/clock.rs index 69d5beb8c98..9b0915a0d1f 100644 --- a/tokio/src/time/clock.rs +++ b/tokio/src/time/clock.rs @@ -28,9 +28,9 @@ cfg_not_test_util! { } cfg_test_util! { - use crate::time::{Duration, Instant}; - use crate::loom::sync::Mutex; use crate::loom::sync::atomic::Ordering; + use crate::loom::sync::Mutex; + use crate::time::{Duration, Instant}; use std::sync::atomic::AtomicBool as StdAtomicBool; cfg_rt! { @@ -38,13 +38,13 @@ cfg_test_util! { fn with_clock(f: impl FnOnce(Option<&Clock>) -> Result) -> R { use crate::runtime::Handle; - let res = match Handle::try_current() { + let result = match Handle::try_current() { Ok(handle) => f(Some(handle.inner.driver().clock())), Err(ref e) if e.is_missing_context() => f(None), Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR), }; - match res { + match result { Ok(ret) => ret, Err(msg) => panic!("{}", msg), } @@ -257,7 +257,7 @@ cfg_test_util! { let elapsed = match inner.unfrozen.as_ref() { Some(v) => v.elapsed(), - None => return Err("time is already frozen") + None => return Err("time is already frozen"), }; inner.base += elapsed; inner.unfrozen = None; diff --git a/tokio/tests/io_join.rs b/tokio/tests/io_join.rs index 69b09393311..9b9f1e5ae5b 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,12 +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'])]) - .await - .unwrap() + rw.write_vectored(&[io::IoSlice::new(b"x")]).await.unwrap() ); assert!(rw.is_write_vectored()); diff --git a/tokio/tests/io_panic.rs b/tokio/tests/io_panic.rs index 9e4cda21f3b..048244d8a93 100644 --- a/tokio/tests/io_panic.rs +++ b/tokio/tests/io_panic.rs @@ -19,7 +19,7 @@ impl AsyncRead for RW { _cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - buf.put_slice(&[b'z']); + buf.put_slice(b"z"); Poll::Ready(Ok(())) } } diff --git a/tokio/tests/io_split.rs b/tokio/tests/io_split.rs index 9f17c9eb14e..983982ccaf9 100644 --- a/tokio/tests/io_split.rs +++ b/tokio/tests/io_split.rs @@ -17,7 +17,7 @@ impl AsyncRead for RW { _cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - buf.put_slice(&[b'z']); + buf.put_slice(b"z"); Poll::Ready(Ok(())) } } @@ -101,12 +101,10 @@ fn method_delegation() { assert_eq!(1, r.read(&mut buf).await.unwrap()); assert_eq!(b'z', buf[0]); - assert_eq!(1, w.write(&[b'x']).await.unwrap()); + assert_eq!(1, w.write(b"x").await.unwrap()); assert_eq!( 2, - w.write_vectored(&[io::IoSlice::new(&[b'x'])]) - .await - .unwrap() + w.write_vectored(&[io::IoSlice::new(b"x")]).await.unwrap() ); assert!(w.is_write_vectored()); diff --git a/tokio/tests/time_interval.rs b/tokio/tests/time_interval.rs index 7472a37123c..f72fd22f26b 100644 --- a/tokio/tests/time_interval.rs +++ b/tokio/tests/time_interval.rs @@ -360,7 +360,7 @@ fn ms(n: u64) -> Duration { Duration::from_millis(n) } -/// Helper struct to test the [tokio::time::Interval::poll_tick()] method. +/// Helper struct to test the [`tokio::time::Interval::poll_tick()`] method. /// /// `poll_tick()` should register the waker in the context only if it returns /// `Poll::Pending`, not when returning `Poll::Ready`. This struct contains an diff --git a/tokio/tests/udp.rs b/tokio/tests/udp.rs index 2f841abfe29..f6b2989e4c5 100644 --- a/tokio/tests/udp.rs +++ b/tokio/tests/udp.rs @@ -372,7 +372,7 @@ async fn try_send_spawn() { .unwrap(); assert_eq!(sent, &MSG_LEN); let mut buf = [0u8; 32]; - let mut received = receiver.recv(&mut buf[..]).await.unwrap(); + let mut bytes_received = receiver.recv(&mut buf[..]).await.unwrap(); sender .connect(receiver.local_addr().unwrap()) @@ -380,7 +380,7 @@ async fn try_send_spawn() { .unwrap(); let sent = &sender.try_send(MSG2).unwrap(); assert_eq!(sent, &MSG2_LEN); - received += receiver.recv(&mut buf[..]).await.unwrap(); + bytes_received += receiver.recv(&mut buf[..]).await.unwrap(); std::thread::spawn(move || { let sent = &sender.try_send(MSG).unwrap(); @@ -388,9 +388,9 @@ async fn try_send_spawn() { }) .join() .unwrap(); - received += receiver.recv(&mut buf[..]).await.unwrap(); + bytes_received += receiver.recv(&mut buf[..]).await.unwrap(); - assert_eq!(received, MSG_LEN * 2 + MSG2_LEN); + assert_eq!(bytes_received, MSG_LEN * 2 + MSG2_LEN); } #[tokio::test]