diff options
author | bdonlan <bdonlan@gmail.com> | 2020-10-08 17:14:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 17:14:39 -0700 |
commit | b704c53b9cc76eaf8c9c6585f8444c4515d27728 (patch) | |
tree | 45d8037ebcd0c1a51b5afa5c0486752aebe103e3 | |
parent | 066965cd59d01fd9d999152e32169a24dfe434fa (diff) |
chore: Fix clippy lints (#2931)
Closes: #2929
Co-authored-by: Bryan Donlan <bdonlan@amazon.com>
-rw-r--r-- | tokio-util/tests/time_delay_queue.rs | 4 | ||||
-rw-r--r-- | tokio/src/runtime/enter.rs | 6 | ||||
-rw-r--r-- | tokio/src/runtime/task/error.rs | 10 | ||||
-rw-r--r-- | tokio/src/sync/batch_semaphore.rs | 10 | ||||
-rw-r--r-- | tokio/src/time/error.rs | 15 | ||||
-rw-r--r-- | tokio/tests/macros_select.rs | 2 | ||||
-rw-r--r-- | tokio/tests/rt_common.rs | 4 | ||||
-rw-r--r-- | tokio/tests/stream_stream_map.rs | 14 | ||||
-rw-r--r-- | tokio/tests/sync_broadcast.rs | 5 |
9 files changed, 20 insertions, 50 deletions
diff --git a/tokio-util/tests/time_delay_queue.rs b/tokio-util/tests/time_delay_queue.rs index 73951e7c..42a56b8b 100644 --- a/tokio-util/tests/time_delay_queue.rs +++ b/tokio-util/tests/time_delay_queue.rs @@ -59,7 +59,7 @@ async fn multi_immediate_delays() { let entry = assert_ready!(poll!(queue)); assert!(entry.is_none()); - res.sort(); + res.sort_unstable(); assert_eq!("1", res[0]); assert_eq!("2", res[1]); @@ -438,7 +438,7 @@ async fn insert_after_ready_poll() { queue.insert_at("foo", now + ms(500)); } - res.sort(); + res.sort_unstable(); assert_eq!("1", res[0]); assert_eq!("2", res[1]); diff --git a/tokio/src/runtime/enter.rs b/tokio/src/runtime/enter.rs index bb6e6be0..f934162b 100644 --- a/tokio/src/runtime/enter.rs +++ b/tokio/src/runtime/enter.rs @@ -13,11 +13,7 @@ pub(crate) enum EnterContext { impl EnterContext { pub(crate) fn is_entered(self) -> bool { - if let EnterContext::Entered { .. } = self { - true - } else { - false - } + matches!(self, EnterContext::Entered { .. }) } } diff --git a/tokio/src/runtime/task/error.rs b/tokio/src/runtime/task/error.rs index dfdec44c..509642d4 100644 --- a/tokio/src/runtime/task/error.rs +++ b/tokio/src/runtime/task/error.rs @@ -30,10 +30,7 @@ impl JoinError { /// Returns true if the error was caused by the task being cancelled pub fn is_cancelled(&self) -> bool { - match &self.repr { - Repr::Cancelled => true, - _ => false, - } + matches!(&self.repr, Repr::Cancelled) } /// Returns true if the error was caused by the task panicking @@ -53,10 +50,7 @@ impl JoinError { /// } /// ``` pub fn is_panic(&self) -> bool { - match &self.repr { - Repr::Panic(_) => true, - _ => false, - } + matches!(&self.repr, Repr::Panic(_)) } /// Consumes the join error, returning the object with which the task panicked. diff --git a/tokio/src/sync/batch_semaphore.rs b/tokio/src/sync/batch_semaphore.rs index 148e8316..d09528be 100644 --- a/tokio/src/sync/batch_semaphore.rs +++ b/tokio/src/sync/batch_semaphore.rs @@ -527,20 +527,14 @@ impl TryAcquireError { /// Returns `true` if the error was caused by a closed semaphore. #[allow(dead_code)] // may be used later! pub(crate) fn is_closed(&self) -> bool { - match self { - TryAcquireError::Closed => true, - _ => false, - } + matches!(self, TryAcquireError::Closed) } /// Returns `true` if the error was caused by calling `try_acquire` on a /// semaphore with no available permits. #[allow(dead_code)] // may be used later! pub(crate) fn is_no_permits(&self) -> bool { - match self { - TryAcquireError::NoPermits => true, - _ => false, - } + matches!(self, TryAcquireError::NoPermits) } } diff --git a/tokio/src/time/error.rs b/tokio/src/time/error.rs index 2f93d671..a022f78f 100644 --- a/tokio/src/time/error.rs +++ b/tokio/src/time/error.rs @@ -40,10 +40,7 @@ impl Error { /// Returns `true` if the error was caused by the timer being shutdown. pub fn is_shutdown(&self) -> bool { - match self.0 { - Kind::Shutdown => true, - _ => false, - } + matches!(self.0, Kind::Shutdown) } /// Creates an error representing a timer at capacity. @@ -53,10 +50,7 @@ impl Error { /// Returns `true` if the error was caused by the timer being at capacity. pub fn is_at_capacity(&self) -> bool { - match self.0 { - Kind::AtCapacity => true, - _ => false, - } + matches!(self.0, Kind::AtCapacity) } /// Create an error representing a misconfigured timer. @@ -66,10 +60,7 @@ impl Error { /// Returns `true` if the error was caused by the timer being misconfigured. pub fn is_invalid(&self) -> bool { - match self.0 { - Kind::Invalid => true, - _ => false, - } + matches!(self.0, Kind::Invalid) } pub(crate) fn as_u8(&self) -> u8 { diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index f971409b..f77f3f01 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -152,7 +152,7 @@ async fn select_streams() { } } - msgs.sort(); + msgs.sort_unstable(); assert_eq!(&msgs[..], &[1, 2, 3]); } diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 93d6a44e..56ab840d 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -206,7 +206,7 @@ rt_test! { out.push(i); } - out.sort(); + out.sort_unstable(); out }); @@ -265,7 +265,7 @@ rt_test! { out.push(i); } - out.sort(); + out.sort_unstable(); out }).await.unwrap() }); diff --git a/tokio/tests/stream_stream_map.rs b/tokio/tests/stream_stream_map.rs index 6b498032..38bb0c5d 100644 --- a/tokio/tests/stream_stream_map.rs +++ b/tokio/tests/stream_stream_map.rs @@ -115,7 +115,7 @@ async fn multiple_entries() { assert_pending!(map.poll_next()); - v.sort(); + v.sort_unstable(); assert_eq!(v[0].0, "bar"); assert_eq!(v[0].1, 4); assert_eq!(v[1].0, "foo"); @@ -213,8 +213,7 @@ fn new_capacity_zero() { let map = StreamMap::<&str, stream::Pending<()>>::new(); assert_eq!(0, map.capacity()); - let keys = map.keys().collect::<Vec<_>>(); - assert!(keys.is_empty()); + assert!(map.keys().next().is_none()); } #[test] @@ -222,8 +221,7 @@ fn with_capacity() { let map = StreamMap::<&str, stream::Pending<()>>::with_capacity(10); assert!(10 <= map.capacity()); - let keys = map.keys().collect::<Vec<_>>(); - assert!(keys.is_empty()); + assert!(map.keys().next().is_none()); } #[test] @@ -235,7 +233,7 @@ fn iter_keys() { map.insert("c", pending()); let mut keys = map.keys().collect::<Vec<_>>(); - keys.sort(); + keys.sort_unstable(); assert_eq!(&keys[..], &[&"a", &"b", &"c"]); } @@ -250,7 +248,7 @@ fn iter_values() { let mut size_hints = map.values().map(|s| s.size_hint().0).collect::<Vec<_>>(); - size_hints.sort(); + size_hints.sort_unstable(); assert_eq!(&size_hints[..], &[1, 2, 3]); } @@ -268,7 +266,7 @@ fn iter_values_mut() { .map(|s: &mut _| s.size_hint().0) .collect::<Vec<_>>(); - size_hints.sort(); + size_hints.sort_unstable(); assert_eq!(&size_hints[..], &[1, 2, 3]); } diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index d7e77e9d..7960eb85 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -492,8 +492,5 @@ fn lagging_receiver_recovers_after_wrap_open() { } fn is_closed(err: broadcast::RecvError) -> bool { - match err { - broadcast::RecvError::Closed => true, - _ => false, - } + matches!(err, broadcast::RecvError::Closed) } |