Skip to content

Commit

Permalink
chore: address clippy lints and bump ci clippy stable
Browse files Browse the repository at this point in the history
superseeds #5248, sorry @drHuangMHT only saw yours now, can you review this one?
https://github.com/libp2p/rust-libp2p/actions/runs/8377129630/job/22938498078?pr=5253#step:6:843 is a bug, see [here](rust-lang/rust-clippy#12377)
Thanks!

Pull-Request: #5253.
  • Loading branch information
jxs authored and guillaumemichel committed Mar 28, 2024
1 parent 8afa8ee commit 0aef95c
Show file tree
Hide file tree
Showing 73 changed files with 111 additions and 292 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Extract version from manifest
run: |
CRATE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version')
echo "CRATE_VERSION=$CRATE_VERSION" >> $GITHUB_ENV
- name: Enforce version in `workspace.dependencies` matches latest version
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
fail-fast: false
matrix:
rust-version: [
1.75.0, # current stable
1.77.0, # current stable
beta,
]
steps:
Expand Down
1 change: 0 additions & 1 deletion core/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use libp2p_identity::Keypair;
use libp2p_identity::PeerId;
use libp2p_identity::SigningError;
use quick_protobuf::{BytesReader, Writer};
use std::convert::TryInto;

const PAYLOAD_TYPE: &str = "/libp2p/routing-state-record";
const DOMAIN_SEP: &str = "libp2p-routing-state";
Expand Down
2 changes: 1 addition & 1 deletion core/src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mod tests {
expected: Multiaddr,
}

let tests = vec![
let tests = [
// Basic ipv4.
Test {
original: "/ip4/192.0.2.1/tcp/1".parse().unwrap(),
Expand Down
8 changes: 1 addition & 7 deletions core/src/transport/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@

use crate::transport::{ListenerId, Transport, TransportError, TransportEvent};
use fnv::FnvHashMap;
use futures::{
channel::mpsc,
future::{self, Ready},
prelude::*,
task::Context,
task::Poll,
};
use futures::{channel::mpsc, future::Ready, prelude::*, task::Context, task::Poll};
use multiaddr::{Multiaddr, Protocol};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion core/src/upgrade/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeError};
use crate::{connection::ConnectedPoint, Negotiated};
use futures::{future::Either, prelude::*};
use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture};
use multistream_select::{DialerSelectFuture, ListenerSelectFuture};
use std::{mem, pin::Pin, task::Context, task::Poll};

pub(crate) use multistream_select::Version;
Expand Down
19 changes: 0 additions & 19 deletions examples/autonat/src/bin/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,3 @@ impl Behaviour {
}
}
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
AutoNat(autonat::Event),
Identify(identify::Event),
}

impl From<identify::Event> for Event {
fn from(v: identify::Event) -> Self {
Self::Identify(v)
}
}

impl From<autonat::Event> for Event {
fn from(v: autonat::Event) -> Self {
Self::AutoNat(v)
}
}
19 changes: 0 additions & 19 deletions examples/autonat/src/bin/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,3 @@ impl Behaviour {
}
}
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
AutoNat(autonat::Event),
Identify(identify::Event),
}

impl From<identify::Event> for Event {
fn from(v: identify::Event) -> Self {
Self::Identify(v)
}
}

impl From<autonat::Event> for Event {
fn from(v: autonat::Event) -> Self {
Self::AutoNat(v)
}
}
1 change: 0 additions & 1 deletion identity/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use core::cmp;
use core::fmt;
use core::hash;
use ed25519_dalek::{self as ed25519, Signer as _, Verifier as _};
use std::convert::TryFrom;
use zeroize::Zeroize;

/// An Ed25519 keypair.
Expand Down
14 changes: 6 additions & 8 deletions identity/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@
feature = "ed25519",
feature = "rsa"
))]
use crate::error::OtherVariantError;
use crate::error::{DecodingError, SigningError};
#[cfg(feature = "ed25519")]
use crate::ed25519;
#[cfg(any(
feature = "ecdsa",
feature = "secp256k1",
feature = "ed25519",
feature = "rsa"
))]
use crate::proto;
use crate::error::OtherVariantError;
use crate::error::{DecodingError, SigningError};
#[cfg(any(
feature = "ecdsa",
feature = "secp256k1",
feature = "ed25519",
feature = "rsa"
))]
use quick_protobuf::{BytesReader, Writer};
use crate::proto;
#[cfg(any(
feature = "ecdsa",
feature = "secp256k1",
feature = "ed25519",
feature = "rsa"
))]
use std::convert::TryFrom;

#[cfg(feature = "ed25519")]
use crate::ed25519;
use quick_protobuf::{BytesReader, Writer};

#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
use crate::rsa;
Expand Down
3 changes: 1 addition & 2 deletions identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
//! All key types have functions to enable conversion to/from their binary representations.
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#![allow(unreachable_pub)]
#[cfg(any(
feature = "ecdsa",
feature = "secp256k1",
feature = "ed25519",
feature = "rsa"
))]
mod proto {
#![allow(unreachable_pub)]
include!("generated/mod.rs");
pub(crate) use self::keys_proto::*;
}
Expand Down
2 changes: 1 addition & 1 deletion identity/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#[cfg(feature = "rand")]
use rand::Rng;
use sha2::Digest as _;
use std::{convert::TryFrom, fmt, str::FromStr};
use std::{fmt, str::FromStr};
use thiserror::Error;

/// Local type-alias for multihash.
Expand Down
7 changes: 1 addition & 6 deletions misc/metrics/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::protocol_stack;
use libp2p_identity::PeerId;
use libp2p_swarm::StreamProtocol;
use prometheus_client::collector::Collector;
use prometheus_client::encoding::{DescriptorEncoder, EncodeLabelSet, EncodeMetric};
use prometheus_client::encoding::{DescriptorEncoder, EncodeMetric};
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::gauge::ConstGauge;
use prometheus_client::metrics::MetricType;
Expand Down Expand Up @@ -138,11 +138,6 @@ impl<TBvEv> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv>> for Metrics {
}
}

#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
struct AddressLabels {
protocols: String,
}

#[derive(Default, Debug, Clone)]
struct Peers(Arc<Mutex<HashMap<PeerId, libp2p_identify::Info>>>);

Expand Down
1 change: 0 additions & 1 deletion misc/multistream-select/src/listener_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use futures::prelude::*;
use smallvec::SmallVec;
use std::{
convert::TryFrom as _,
iter::FromIterator,
mem,
pin::Pin,
task::{Context, Poll},
Expand Down
1 change: 0 additions & 1 deletion misc/multistream-select/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::Version;
use bytes::{BufMut, Bytes, BytesMut};
use futures::{io::IoSlice, prelude::*, ready};
use std::{
convert::TryFrom,
error::Error,
fmt, io,
pin::Pin,
Expand Down
1 change: 0 additions & 1 deletion misc/quick-protobuf-codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl From<Error> for io::Error {
#[cfg(test)]
mod tests {
use super::*;
use crate::proto;
use asynchronous_codec::FramedRead;
use futures::io::Cursor;
use futures::{FutureExt, StreamExt};
Expand Down
2 changes: 1 addition & 1 deletion misc/rw-stream-sink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ where
mod tests {
use super::RwStreamSink;
use async_std::task;
use futures::{channel::mpsc, prelude::*, stream};
use futures::{channel::mpsc, prelude::*};
use std::{
pin::Pin,
task::{Context, Poll},
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use config::{MaxBufferBehaviour, MplexConfig};

use bytes::Bytes;
use codec::LocalStreamId;
use futures::{future, prelude::*, ready};
use futures::{prelude::*, ready};
use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent};
use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo};
use parking_lot::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion muxers/yamux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use either::Either;
use futures::{future, prelude::*, ready};
use futures::{prelude::*, ready};
use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent};
use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo};
use std::collections::VecDeque;
Expand Down
10 changes: 3 additions & 7 deletions protocols/autonat/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libp2p_core::Multiaddr;
use libp2p_identity::PeerId;
use libp2p_request_response::{self as request_response};
use libp2p_swarm::StreamProtocol;
use std::{convert::TryFrom, io};
use std::io;

/// The protocol name used for negotiating with multistream-select.
pub const DEFAULT_PROTOCOL_NAME: StreamProtocol = StreamProtocol::new("/libp2p/autonat/1.0.0");
Expand Down Expand Up @@ -121,12 +121,8 @@ impl DialRequest {
}

let peer_id_result = msg.dial.and_then(|dial| {
dial.peer.and_then(|peer_info| {
let Some(peer_id) = peer_info.id else {
return None;
};
Some((peer_id, peer_info.addrs))
})
dial.peer
.and_then(|peer_info| peer_info.id.map(|peer_id| (peer_id, peer_info.addrs)))
});

let (peer_id, addrs) = peer_id_result
Expand Down
6 changes: 3 additions & 3 deletions protocols/dcutr/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ impl NetworkBehaviour for Behaviour {
.insert(connection_id);

assert!(
self.direct_to_relayed_connections
.get(&connection_id)
.is_none(),
!self
.direct_to_relayed_connections
.contains_key(&connection_id),
"state mismatch"
);

Expand Down
1 change: 0 additions & 1 deletion protocols/dcutr/src/protocol/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use asynchronous_codec::Framed;
use futures::prelude::*;
use libp2p_core::{multiaddr::Protocol, Multiaddr};
use libp2p_swarm::Stream;
use std::convert::TryFrom;
use std::io;
use thiserror::Error;

Expand Down
1 change: 0 additions & 1 deletion protocols/dcutr/src/protocol/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use futures_timer::Delay;
use instant::Instant;
use libp2p_core::{multiaddr::Protocol, Multiaddr};
use libp2p_swarm::Stream;
use std::convert::TryFrom;
use std::io;
use thiserror::Error;

Expand Down
4 changes: 2 additions & 2 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ where
return Err(SubscriptionError::NotAllowed);
}

if self.mesh.get(&topic_hash).is_some() {
if self.mesh.contains_key(&topic_hash) {
tracing::debug!(%topic, "Topic is already in the mesh");
return Ok(false);
}
Expand All @@ -554,7 +554,7 @@ where
tracing::debug!(%topic, "Unsubscribing from topic");
let topic_hash = topic.hash();

if self.mesh.get(&topic_hash).is_none() {
if !self.mesh.contains_key(&topic_hash) {
tracing::debug!(topic=%topic_hash, "Already unsubscribed from topic");
// we are not subscribed
return Ok(false);
Expand Down
Loading

0 comments on commit 0aef95c

Please sign in to comment.