From be9328da75c34b14dbbf017c344fee6219985559 Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Mon, 8 Apr 2024 13:44:18 +0200 Subject: [PATCH] chore: fix clippy warnings (#6466) --- examples/tinyhttp.rs | 4 ++-- tokio-stream/src/stream_map.rs | 8 ++++---- tokio-stream/tests/async_send_sync.rs | 3 +++ tokio-stream/tests/stream_timeout.rs | 2 +- tokio-util/src/sync/cancellation_token/tree_node.rs | 2 +- tokio-util/src/task/spawn_pinned.rs | 2 +- tokio/src/fs/open_options.rs | 1 - tokio/src/runtime/io/scheduled_io.rs | 2 +- tokio/src/sync/tests/atomic_waker.rs | 3 +++ tokio/tests/async_send_sync.rs | 7 +++++++ tokio/tests/sync_broadcast.rs | 1 + tokio/tests/sync_mpsc.rs | 1 + tokio/tests/sync_notify.rs | 1 + tokio/tests/sync_once_cell.rs | 1 - tokio/tests/sync_oneshot.rs | 3 +++ 15 files changed, 29 insertions(+), 12 deletions(-) diff --git a/examples/tinyhttp.rs b/examples/tinyhttp.rs index 8c6184f94..dceccf47a 100644 --- a/examples/tinyhttp.rs +++ b/examples/tinyhttp.rs @@ -259,11 +259,11 @@ mod date { unix_date: u64, } - thread_local!(static LAST: RefCell = RefCell::new(LastRenderedNow { + thread_local!(static LAST: RefCell = const { RefCell::new(LastRenderedNow { bytes: [0; 128], amt: 0, unix_date: 0, - })); + }) }); impl fmt::Display for Now { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/tokio-stream/src/stream_map.rs b/tokio-stream/src/stream_map.rs index 41ab9648c..cefedcd7e 100644 --- a/tokio-stream/src/stream_map.rs +++ b/tokio-stream/src/stream_map.rs @@ -467,10 +467,10 @@ impl StreamMap { /// assert!(map.remove(&1).is_some()); /// assert!(map.remove(&1).is_none()); /// ``` - pub fn remove(&mut self, k: &Q) -> Option + pub fn remove(&mut self, k: &Q) -> Option where K: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { for i in 0..self.entries.len() { if self.entries[i].0.borrow() == k { @@ -496,10 +496,10 @@ impl StreamMap { /// assert_eq!(map.contains_key(&1), true); /// assert_eq!(map.contains_key(&2), false); /// ``` - pub fn contains_key(&self, k: &Q) -> bool + pub fn contains_key(&self, k: &Q) -> bool where K: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { for i in 0..self.entries.len() { if self.entries[i].0.borrow() == k { diff --git a/tokio-stream/tests/async_send_sync.rs b/tokio-stream/tests/async_send_sync.rs index f1c8b4efe..23d50d081 100644 --- a/tokio-stream/tests/async_send_sync.rs +++ b/tokio-stream/tests/async_send_sync.rs @@ -15,18 +15,21 @@ fn require_unpin(_t: &T) {} #[allow(dead_code)] struct Invalid; +#[allow(unused)] trait AmbiguousIfSend { fn some_item(&self) {} } impl AmbiguousIfSend<()> for T {} impl AmbiguousIfSend for T {} +#[allow(unused)] trait AmbiguousIfSync { fn some_item(&self) {} } impl AmbiguousIfSync<()> for T {} impl AmbiguousIfSync for T {} +#[allow(unused)] trait AmbiguousIfUnpin { fn some_item(&self) {} } diff --git a/tokio-stream/tests/stream_timeout.rs b/tokio-stream/tests/stream_timeout.rs index 2338f8335..19b4c3d53 100644 --- a/tokio-stream/tests/stream_timeout.rs +++ b/tokio-stream/tests/stream_timeout.rs @@ -1,7 +1,7 @@ #![cfg(all(feature = "time", feature = "sync", feature = "io-util"))] use tokio::time::{self, sleep, Duration}; -use tokio_stream::{self, StreamExt}; +use tokio_stream::StreamExt; use tokio_test::*; use futures::stream; diff --git a/tokio-util/src/sync/cancellation_token/tree_node.rs b/tokio-util/src/sync/cancellation_token/tree_node.rs index f042e4e79..d2d7e89f6 100644 --- a/tokio-util/src/sync/cancellation_token/tree_node.rs +++ b/tokio-util/src/sync/cancellation_token/tree_node.rs @@ -206,7 +206,7 @@ fn move_children_to_parent(node: &mut Inner, parent: &mut Inner) { for child in std::mem::take(&mut node.children) { { let mut child_locked = child.inner.lock().unwrap(); - child_locked.parent = node.parent.clone(); + child_locked.parent.clone_from(&node.parent); child_locked.parent_idx = parent.children.len(); } parent.children.push(child); diff --git a/tokio-util/src/task/spawn_pinned.rs b/tokio-util/src/task/spawn_pinned.rs index b4102ec72..5e4d6cda3 100644 --- a/tokio-util/src/task/spawn_pinned.rs +++ b/tokio-util/src/task/spawn_pinned.rs @@ -23,7 +23,7 @@ use tokio::task::{spawn_local, JoinHandle, LocalSet}; /// /// ``` /// use std::rc::Rc; -/// use tokio::{self, task }; +/// use tokio::task; /// use tokio_util::task::LocalPoolHandle; /// /// #[tokio::main(flavor = "current_thread")] diff --git a/tokio/src/fs/open_options.rs b/tokio/src/fs/open_options.rs index 6e2aa0cdf..126153938 100644 --- a/tokio/src/fs/open_options.rs +++ b/tokio/src/fs/open_options.rs @@ -442,7 +442,6 @@ feature! { /// # Examples /// /// ```no_run - /// use libc; /// use tokio::fs::OpenOptions; /// use std::io; /// diff --git a/tokio/src/runtime/io/scheduled_io.rs b/tokio/src/runtime/io/scheduled_io.rs index 527bb9808..cf25b6386 100644 --- a/tokio/src/runtime/io/scheduled_io.rs +++ b/tokio/src/runtime/io/scheduled_io.rs @@ -346,7 +346,7 @@ impl ScheduledIo { match slot { Some(existing) => { if !existing.will_wake(cx.waker()) { - *existing = cx.waker().clone(); + existing.clone_from(cx.waker()); } } None => { diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index 8a1201287..d89b44fa4 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -3,7 +3,10 @@ use tokio_test::task; use std::task::Waker; +#[allow(unused)] trait AssertSend: Send {} + +#[allow(unused)] trait AssertSync: Sync {} impl AssertSend for AtomicWaker {} diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index dfd26f9e9..52b3835b7 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -14,16 +14,19 @@ use tokio::time::{Duration, Instant}; // The names of these structs behaves better when sorted. // Send: Yes, Sync: Yes #[derive(Clone)] +#[allow(unused)] struct YY {} // Send: Yes, Sync: No #[derive(Clone)] +#[allow(unused)] struct YN { _value: Cell, } // Send: No, Sync: No #[derive(Clone)] +#[allow(unused)] struct NN { _value: Rc, } @@ -52,18 +55,21 @@ fn require_unpin(_t: &T) {} #[allow(dead_code)] struct Invalid; +#[allow(unused)] trait AmbiguousIfSend { fn some_item(&self) {} } impl AmbiguousIfSend<()> for T {} impl AmbiguousIfSend for T {} +#[allow(unused)] trait AmbiguousIfSync { fn some_item(&self) {} } impl AmbiguousIfSync<()> for T {} impl AmbiguousIfSync for T {} +#[allow(unused)] trait AmbiguousIfUnpin { fn some_item(&self) {} } @@ -712,6 +718,7 @@ mod unix_asyncfd { use super::*; use tokio::io::unix::*; + #[allow(unused)] struct ImplsFd { _t: T, } diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index 16b9a0abb..17fe44f3e 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -52,6 +52,7 @@ macro_rules! assert_closed { }; } +#[allow(unused)] trait AssertSend: Send + Sync {} impl AssertSend for broadcast::Sender {} impl AssertSend for broadcast::Receiver {} diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index 4a7eced13..10a805615 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -21,6 +21,7 @@ mod support { pub(crate) mod mpsc_stream; } +#[allow(unused)] trait AssertSend: Send {} impl AssertSend for mpsc::Sender {} impl AssertSend for mpsc::Receiver {} diff --git a/tokio/tests/sync_notify.rs b/tokio/tests/sync_notify.rs index e31b9d49c..01b8ce865 100644 --- a/tokio/tests/sync_notify.rs +++ b/tokio/tests/sync_notify.rs @@ -8,6 +8,7 @@ use tokio::sync::Notify; use tokio_test::task::spawn; use tokio_test::*; +#[allow(unused)] trait AssertSend: Send + Sync {} impl AssertSend for Notify {} diff --git a/tokio/tests/sync_once_cell.rs b/tokio/tests/sync_once_cell.rs index d5a69478e..b662db3ad 100644 --- a/tokio/tests/sync_once_cell.rs +++ b/tokio/tests/sync_once_cell.rs @@ -2,7 +2,6 @@ #![cfg(feature = "full")] use std::mem; -use std::ops::Drop; use std::sync::atomic::{AtomicU32, Ordering}; use std::time::Duration; use tokio::runtime; diff --git a/tokio/tests/sync_oneshot.rs b/tokio/tests/sync_oneshot.rs index 163d50de9..127f7cb61 100644 --- a/tokio/tests/sync_oneshot.rs +++ b/tokio/tests/sync_oneshot.rs @@ -17,13 +17,16 @@ use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; +#[allow(unused)] trait AssertSend: Send {} impl AssertSend for oneshot::Sender {} impl AssertSend for oneshot::Receiver {} +#[allow(unused)] trait SenderExt { fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()>; } + impl SenderExt for oneshot::Sender { fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()> { tokio::pin! {