Skip to content

Commit 8138deb

Browse files
authored
chore(*): fix clippy 1.95.0-beta.3 lints
Fix format and clippy lints. `expect` false positive `clippy::collapsible_match` for some branches where collapsing the if branch into the match statement is not possible. See rust-lang/rust-clippy#16705. Pull-Request: #6288.
1 parent c137d57 commit 8138deb

15 files changed

Lines changed: 49 additions & 56 deletions

File tree

misc/peer-store/src/memory_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ impl<T> Store for MemoryStore<T> {
220220
};
221221

222222
match info.error {
223-
DialError::WrongPeerId { obtained, address } => {
223+
DialError::WrongPeerId { obtained, address }
224+
if self.remove_address_inner(&peer, address, false) =>
225+
{
224226
// The stored peer id is incorrect, remove incorrect and add correct one.
225-
if self.remove_address_inner(&peer, address, false) {
226-
self.add_address_inner(obtained, address, false);
227-
}
227+
self.add_address_inner(obtained, address, false);
228228
}
229229
DialError::Transport(errors) => {
230230
for (addr, _) in errors {

protocols/autonat/src/v2/client/handler/dial_back.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ impl ConnectionHandler for Handler {
7171
match event {
7272
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
7373
protocol, ..
74-
}) => {
74+
}) =>
75+
{
76+
#[allow(clippy::collapsible_match)]
7577
if self.inbound.try_push(perform_dial_back(protocol)).is_err() {
7678
tracing::warn!("Dial back request dropped, too many requests in flight");
7779
}

protocols/autonat/src/v2/client/handler/dial_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl ConnectionHandler for Handler {
188188
}
189189
},
190190
ConnectionEvent::RemoteProtocolsChange(ProtocolsChange::Added(mut added)) => {
191+
#[allow(clippy::collapsible_match)]
191192
if added.any(|p| p.as_ref() == DIAL_REQUEST_PROTOCOL) {
192193
self.queued_events
193194
.push_back(ConnectionHandlerEvent::NotifyBehaviour(

protocols/autonat/src/v2/server/handler/dial_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ where
121121
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
122122
protocol, ..
123123
}) => {
124+
#[allow(clippy::collapsible_match)]
124125
if self
125126
.inbound
126127
.try_push(handle_request(

protocols/gossipsub/src/behaviour.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,14 +3544,12 @@ fn validate_config(
35443544
return Err("Published messages contain an author but incoming messages with an author will be rejected. Consider adjusting the validation or privacy settings in the config");
35453545
}
35463546
}
3547-
ValidationMode::Strict => {
3548-
if !authenticity.is_signing() {
3549-
return Err(
3547+
ValidationMode::Strict if !authenticity.is_signing() => {
3548+
return Err(
35503549
"Messages will be
35513550
published unsigned and incoming unsigned messages will be rejected. Consider adjusting
35523551
the validation or privacy settings in the config"
35533552
);
3554-
}
35553553
}
35563554
_ => {}
35573555
}

protocols/gossipsub/src/behaviour/tests/scoring.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,9 @@ fn test_do_not_gossip_to_peers_below_gossip_threshold() {
293293
RpcOut::IHave(IHave {
294294
topic_hash,
295295
message_ids,
296-
}) => {
297-
if topic_hash == &topics[0] && message_ids.iter().any(|id| id == &msg_id) {
298-
assert_eq!(peer, &p2);
299-
true
300-
} else {
301-
false
302-
}
296+
}) if topic_hash == &topics[0] && message_ids.iter().any(|id| id == &msg_id) => {
297+
assert_eq!(peer, &p2);
298+
true
303299
}
304300
_ => false,
305301
});
@@ -455,13 +451,9 @@ fn test_ihave_msg_from_peer_below_gossip_threshold_gets_ignored() {
455451

456452
// check that we sent exactly one IWANT request to p2
457453
let (control_msgs, _) = count_control_msgs(queues, |peer, c| match c {
458-
RpcOut::IWant(IWant { message_ids }) => {
459-
if message_ids.iter().any(|m| m == &msg_id) {
460-
assert_eq!(peer, &p2);
461-
true
462-
} else {
463-
false
464-
}
454+
RpcOut::IWant(IWant { message_ids }) if message_ids.iter().any(|m| m == &msg_id) => {
455+
assert_eq!(peer, &p2);
456+
true
465457
}
466458
_ => false,
467459
});

protocols/gossipsub/src/handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ impl EnabledHandler {
274274
ref mut timeout,
275275
..
276276
} => {
277+
#[allow(clippy::collapsible_match)]
277278
if Pin::new(timeout).poll(cx).is_ready() {
278279
// Inform the behaviour and end the poll.
279280
self.outbound_substream =

protocols/gossipsub/src/queue.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ impl Queue {
8787

8888
let mut count = 0;
8989
self.non_priority.retain(|message| match message {
90-
RpcOut::Publish { message_id, .. } | RpcOut::Forward { message_id, .. } => {
91-
if message_ids.contains(message_id) {
92-
count += 1;
93-
false
94-
} else {
95-
true
96-
}
90+
RpcOut::Publish { message_id, .. } | RpcOut::Forward { message_id, .. }
91+
if message_ids.contains(message_id) =>
92+
{
93+
count += 1;
94+
false
9795
}
9896
_ => true,
9997
});

protocols/identify/src/behaviour.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ use libp2p_core::{
3333
};
3434
use libp2p_identity::{Keypair, PeerId, PublicKey};
3535
use libp2p_swarm::{
36+
_address_translation,
3637
behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm},
3738
ConnectionDenied, ConnectionId, DialError, ExternalAddresses, ListenAddresses,
3839
NetworkBehaviour, NotifyHandler, PeerAddresses, StreamUpgradeError, THandler, THandlerInEvent,
39-
THandlerOutEvent, ToSwarm, _address_translation,
40+
THandlerOutEvent, ToSwarm,
4041
};
4142

4243
use crate::{

protocols/kad/src/query/peers/closest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ impl ClosestPeersIter {
394394
/// Consumes the iterator, returning the closest peers.
395395
pub fn into_result(self) -> impl Iterator<Item = PeerId> {
396396
self.closest_peers
397-
.into_iter()
398-
.filter_map(|(_, peer)| {
397+
.into_values()
398+
.filter_map(|peer| {
399399
if let PeerState::Succeeded = peer.state {
400400
Some(peer.key.into_preimage())
401401
} else {

0 commit comments

Comments
 (0)