fix: deal with new lints from beta clippy (#3389)

Most of this is trivial, apart from the rename of the `clippy::derive_hash_xor_eq` lint to `clippy::derived_hash_with_manual_eq`.

Instead of allowing that lint, we manually implement `PartialEq` and add a comment why the difference between the `PartialEq` and `Hash` implementations are okay.
This commit is contained in:
Thomas Eizinger
2023-02-01 00:20:26 +11:00
committed by GitHub
parent 3ec7c797e5
commit 8f3b7e3876
5 changed files with 20 additions and 23 deletions

View File

@ -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<H: Hasher>(&self, state: &mut H) {
state.write_u64(self.num);
}

View File

@ -3236,10 +3236,7 @@ fn random_message(seq: &mut u64, topics: &Vec<TopicHash>) -> 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"
);

View File

@ -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> {

View File

@ -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
}
}

View File

@ -1559,7 +1559,6 @@ where
.new_handler()
.inbound_protocol()
.protocol_info()
.into_iter()
.map(|info| info.protocol_name().to_vec())
.collect();