diff --git a/muxers/mplex/src/codec.rs b/muxers/mplex/src/codec.rs index 76dbddb3..48dbd243 100644 --- a/muxers/mplex/src/codec.rs +++ b/muxers/mplex/src/codec.rs @@ -49,7 +49,7 @@ pub(crate) const MAX_FRAME_SIZE: usize = 1024 * 1024; /// > we initiated the stream, so the local ID has the role `Endpoint::Dialer`. /// > Conversely, when receiving a frame with a flag identifying the remote as a "sender", /// > the corresponding local ID has the role `Endpoint::Listener`. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, Eq, Debug)] pub struct LocalStreamId { num: u64, role: Endpoint, @@ -64,8 +64,20 @@ impl fmt::Display for LocalStreamId { } } +/// Manual implementation of [`PartialEq`]. +/// +/// This is equivalent to the derived one but we purposely don't derive it because it triggers the +/// `clippy::derive_hash_xor_eq` lint. +/// +/// This [`PartialEq`] implementation satisfies the rule of v1 == v2 -> hash(v1) == hash(v2). +/// The inverse is not true but does not have to be. +impl PartialEq for LocalStreamId { + fn eq(&self, other: &Self) -> bool { + self.num.eq(&other.num) && self.role.eq(&other.role) + } +} + impl Hash for LocalStreamId { - #![allow(clippy::derive_hash_xor_eq)] fn hash(&self, state: &mut H) { state.write_u64(self.num); } diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 18e08e0e..cc922e47 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -3236,10 +3236,7 @@ fn random_message(seq: &mut u64, topics: &Vec) -> RawMessage { *seq += 1; RawMessage { source: Some(PeerId::random()), - data: (0..rng.gen_range(10..30)) - .into_iter() - .map(|_| rng.gen()) - .collect(), + data: (0..rng.gen_range(10..30)).map(|_| rng.gen()).collect(), sequence_number: Some(*seq), topic: topics[rng.gen_range(0..topics.len())].clone(), signature: None, @@ -4311,7 +4308,6 @@ fn test_opportunistic_grafting() { //add additional 5 peers let others: Vec<_> = (0..5) - .into_iter() .map(|_| add_peer(&mut gs, &topics, false, false)) .collect(); @@ -4670,7 +4666,7 @@ fn test_limit_number_of_message_ids_inside_ihave() { (this may fail with a probability < 10^-58" ); assert!( - ihaves1.intersection(&ihaves2).into_iter().count() > 0, + ihaves1.intersection(&ihaves2).count() > 0, "should have sent random messages with some common messages to p1 and p2 \ (this may fail with a probability < 10^-58" ); diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index d7d43392..3545f970 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -636,20 +636,15 @@ pub enum NotifyHandler { } /// The options which connections to close. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub enum CloseConnection { /// Disconnect a particular connection. One(ConnectionId), /// Disconnect all connections. + #[default] All, } -impl Default for CloseConnection { - fn default() -> Self { - CloseConnection::All - } -} - /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). pub enum FromSwarm<'a, Handler: IntoConnectionHandler> { diff --git a/swarm/src/dial_opts.rs b/swarm/src/dial_opts.rs index eb375c6c..77425f00 100644 --- a/swarm/src/dial_opts.rs +++ b/swarm/src/dial_opts.rs @@ -320,11 +320,12 @@ impl WithoutPeerIdWithAddress { /// .condition(PeerCondition::Disconnected) /// .build(); /// ``` -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Default)] pub enum PeerCondition { /// A new dialing attempt is initiated _only if_ the peer is currently /// considered disconnected, i.e. there is no established connection /// and no ongoing dialing attempt. + #[default] Disconnected, /// A new dialing attempt is initiated _only if_ there is currently /// no ongoing dialing attempt, i.e. the peer is either considered @@ -334,9 +335,3 @@ pub enum PeerCondition { /// configured connection limits. Always, } - -impl Default for PeerCondition { - fn default() -> Self { - PeerCondition::Disconnected - } -} diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 401aa02d..bdef527e 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1559,7 +1559,6 @@ where .new_handler() .inbound_protocol() .protocol_info() - .into_iter() .map(|info| info.protocol_name().to_vec()) .collect();