From 950b0be0feadffa36db81d548bc666863c9b1a8f Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 28 Nov 2024 09:47:07 +0800 Subject: [PATCH] fix(ci): Clippy Beta --- protocols/gossipsub/src/backoff.rs | 2 +- protocols/gossipsub/src/behaviour.rs | 2 +- protocols/kad/src/jobs.rs | 2 +- protocols/kad/src/kbucket.rs | 4 ++-- protocols/kad/src/kbucket/bucket.rs | 4 ++-- protocols/kad/src/record.rs | 4 ++-- swarm/src/connection/pool.rs | 2 +- transports/noise/src/io/handshake.rs | 2 +- transports/websocket-websys/src/lib.rs | 2 ++ transports/webtransport-websys/src/lib.rs | 2 ++ wasm-tests/webtransport-tests/src/lib.rs | 2 ++ 11 files changed, 17 insertions(+), 11 deletions(-) diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index 4414ffb00e6..c955ee59c65 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -124,7 +124,7 @@ impl BackoffStorage { pub(crate) fn is_backoff_with_slack(&self, topic: &TopicHash, peer: &PeerId) -> bool { self.backoffs .get(topic) - .map_or(false, |m| m.contains_key(peer)) + .is_some_and(|m| m.contains_key(peer)) } pub(crate) fn get_backoff_time(&self, topic: &TopicHash, peer: &PeerId) -> Option { diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 075a881db48..ae808d97261 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1689,7 +1689,7 @@ where let self_published = !self.config.allow_self_origin() && if let Some(own_id) = self.publish_config.get_own_id() { own_id != propagation_source - && raw_message.source.as_ref().map_or(false, |s| s == own_id) + && raw_message.source.as_ref().is_some_and(|s| s == own_id) } else { self.published_message_ids.contains(msg_id) }; diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 537f652b7a4..fa558878a38 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -203,7 +203,7 @@ impl PutRecordJob { T: RecordStore, { if self.inner.check_ready(cx, now) { - let publish = self.next_publish.map_or(false, |t_pub| now >= t_pub); + let publish = self.next_publish.is_some_and(|t_pub| now >= t_pub); let records = store .records() .filter_map(|r| { diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index 28d7df03917..99d534fa669 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -529,12 +529,12 @@ where /// Returns true if the bucket has a pending node. pub fn has_pending(&self) -> bool { - self.bucket.pending().map_or(false, |n| !n.is_ready()) + self.bucket.pending().is_some_and(|n| !n.is_ready()) } /// Tests whether the given distance falls into this bucket. pub fn contains(&self, d: &Distance) -> bool { - BucketIndex::new(d).map_or(false, |i| i == self.index) + BucketIndex::new(d).is_some_and(|i| i == self.index) } /// Generates a random distance that falls into this bucket. diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index 1426017aa7a..ec2b7756c43 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -377,7 +377,7 @@ where // Adjust `first_connected_pos` accordingly. match status { NodeStatus::Connected => { - if self.first_connected_pos.map_or(false, |p| p == pos.0) + if self.first_connected_pos.is_some_and(|p| p == pos.0) && pos.0 == self.nodes.len() { // It was the last connected node. @@ -398,7 +398,7 @@ where /// Returns the status of the node at the given position. pub(crate) fn status(&self, pos: Position) -> NodeStatus { - if self.first_connected_pos.map_or(false, |i| pos.0 >= i) { + if self.first_connected_pos.is_some_and(|i| pos.0 >= i) { NodeStatus::Connected } else { NodeStatus::Disconnected diff --git a/protocols/kad/src/record.rs b/protocols/kad/src/record.rs index cb7c4b866fc..b8a644acdd6 100644 --- a/protocols/kad/src/record.rs +++ b/protocols/kad/src/record.rs @@ -101,7 +101,7 @@ impl Record { /// Checks whether the record is expired w.r.t. the given `Instant`. pub fn is_expired(&self, now: Instant) -> bool { - self.expires.map_or(false, |t| now >= t) + self.expires.is_some_and(|t| now >= t) } } @@ -154,7 +154,7 @@ impl ProviderRecord { /// Checks whether the provider record is expired w.r.t. the given `Instant`. pub fn is_expired(&self, now: Instant) -> bool { - self.expires.map_or(false, |t| now >= t) + self.expires.is_some_and(|t| now >= t) } } diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index b2accf745ef..7964ecbfa69 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -207,7 +207,7 @@ struct PendingConnection { impl PendingConnection { fn is_for_same_remote_as(&self, other: PeerId) -> bool { - self.peer_id.map_or(false, |peer| peer == other) + self.peer_id == Some(other) } /// Aborts the connection attempt, closing the connection. diff --git a/transports/noise/src/io/handshake.rs b/transports/noise/src/io/handshake.rs index 8993a5795b6..d8dfb9b802e 100644 --- a/transports/noise/src/io/handshake.rs +++ b/transports/noise/src/io/handshake.rs @@ -106,7 +106,7 @@ where .id_remote_pubkey .ok_or_else(|| Error::AuthenticationFailed)?; - let is_valid_signature = self.dh_remote_pubkey_sig.as_ref().map_or(false, |s| { + let is_valid_signature = self.dh_remote_pubkey_sig.as_ref().is_some_and(|s| { id_pk.verify(&[STATIC_KEY_DOMAIN.as_bytes(), pubkey.as_ref()].concat(), s) }); diff --git a/transports/websocket-websys/src/lib.rs b/transports/websocket-websys/src/lib.rs index 17b07c71c0a..21789eeca66 100644 --- a/transports/websocket-websys/src/lib.rs +++ b/transports/websocket-websys/src/lib.rs @@ -20,6 +20,8 @@ //! Libp2p websocket transports built on [web-sys](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html). +#![allow(unexpected_cfgs)] + mod web_context; use bytes::BytesMut; diff --git a/transports/webtransport-websys/src/lib.rs b/transports/webtransport-websys/src/lib.rs index f9c59694fa3..dcb1010d986 100644 --- a/transports/webtransport-websys/src/lib.rs +++ b/transports/webtransport-websys/src/lib.rs @@ -1,5 +1,7 @@ //! Libp2p WebTransport built on [web-sys](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html) +#![allow(unexpected_cfgs)] + mod bindings; mod connection; mod endpoint; diff --git a/wasm-tests/webtransport-tests/src/lib.rs b/wasm-tests/webtransport-tests/src/lib.rs index 938cdf0b3e1..4cf4375bf7a 100644 --- a/wasm-tests/webtransport-tests/src/lib.rs +++ b/wasm-tests/webtransport-tests/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unexpected_cfgs)] + use futures::channel::oneshot; use futures::{AsyncReadExt, AsyncWriteExt}; use getrandom::getrandom;