From 0aef95c7d9dc5bc17744a0403f573ed7de4419f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Mon, 25 Mar 2024 00:33:12 +0000 Subject: [PATCH] chore: address clippy lints and bump ci clippy stable 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](https://github.com/rust-lang/rust-clippy/issues/12377) Thanks! Pull-Request: #5253. --- .github/workflows/ci.yml | 4 +- core/src/peer_record.rs | 1 - core/src/translation.rs | 2 +- core/src/transport/memory.rs | 8 +-- core/src/upgrade/apply.rs | 2 +- examples/autonat/src/bin/autonat_client.rs | 19 ------- examples/autonat/src/bin/autonat_server.rs | 19 ------- identity/src/ed25519.rs | 1 - identity/src/keypair.rs | 14 +++-- identity/src/lib.rs | 3 +- identity/src/peer_id.rs | 2 +- misc/metrics/src/identify.rs | 7 +-- .../multistream-select/src/listener_select.rs | 1 - misc/multistream-select/src/protocol.rs | 1 - misc/quick-protobuf-codec/src/lib.rs | 1 - misc/rw-stream-sink/src/lib.rs | 2 +- muxers/mplex/src/lib.rs | 2 +- muxers/yamux/src/lib.rs | 2 +- protocols/autonat/src/protocol.rs | 10 ++-- protocols/dcutr/src/behaviour.rs | 6 +-- protocols/dcutr/src/protocol/inbound.rs | 1 - protocols/dcutr/src/protocol/outbound.rs | 1 - protocols/gossipsub/src/behaviour.rs | 4 +- protocols/gossipsub/src/behaviour/tests.rs | 27 ++++------ protocols/gossipsub/src/config.rs | 2 - protocols/gossipsub/src/mcache.rs | 4 +- protocols/gossipsub/src/peer_score.rs | 6 +-- protocols/gossipsub/src/protocol.rs | 1 - .../gossipsub/src/subscription_filter.rs | 1 - protocols/identify/src/protocol.rs | 1 - protocols/kad/src/behaviour/test.rs | 18 ++----- protocols/kad/src/kbucket.rs | 2 +- protocols/kad/src/kbucket/bucket.rs | 1 - protocols/kad/src/kbucket/entry.rs | 2 +- protocols/kad/src/protocol.rs | 2 +- protocols/kad/src/query/peers/closest.rs | 6 +-- .../kad/src/query/peers/closest/disjoint.rs | 19 +------ protocols/kad/src/query/peers/fixed.rs | 1 - protocols/kad/src/record/store/memory.rs | 3 -- protocols/mdns/src/behaviour/iface/dns.rs | 1 - protocols/mdns/src/behaviour/socket.rs | 1 - protocols/mdns/src/behaviour/timer.rs | 5 +- protocols/ping/src/protocol.rs | 2 - protocols/relay/src/behaviour/rate_limiter.rs | 2 - protocols/relay/src/copy_future.rs | 6 +-- protocols/rendezvous/src/codec.rs | 2 - protocols/rendezvous/src/server.rs | 2 - protocols/rendezvous/tests/rendezvous.rs | 1 - protocols/request-response/src/cbor.rs | 1 - protocols/request-response/src/json.rs | 1 - protocols/request-response/tests/ping.rs | 2 +- swarm/src/behaviour/peer_addresses.rs | 2 +- swarm/src/connection.rs | 29 +++++----- swarm/src/connection/pool.rs | 27 +--------- swarm/src/handler/multi.rs | 2 +- swarm/src/handler/one_shot.rs | 2 +- swarm/src/lib.rs | 9 +--- swarm/tests/swarm_derive.rs | 53 +++++++++---------- transports/dns/src/lib.rs | 8 +-- transports/noise/src/io/handshake.rs | 2 +- transports/noise/src/protocol.rs | 2 - transports/noise/tests/smoke.rs | 2 +- transports/quic/src/transport.rs | 4 +- transports/tcp/src/lib.rs | 6 +-- transports/tcp/src/provider/tokio.rs | 1 - transports/uds/src/lib.rs | 2 +- .../src/stream/poll_data_channel.rs | 2 +- transports/webrtc/src/tokio/transport.rs | 6 +-- transports/websocket-websys/src/lib.rs | 2 +- .../websocket-websys/src/web_context.rs | 2 +- transports/websocket/src/framed.rs | 2 +- transports/websocket/src/quicksink.rs | 2 +- transports/websocket/src/tls.rs | 1 - 73 files changed, 111 insertions(+), 292 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a489fec1f1f..9069b2eecf1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -234,7 +234,7 @@ jobs: fail-fast: false matrix: rust-version: [ - 1.75.0, # current stable + 1.77.0, # current stable beta, ] steps: diff --git a/core/src/peer_record.rs b/core/src/peer_record.rs index 2fd6a39ef2b..d5fc86c391e 100644 --- a/core/src/peer_record.rs +++ b/core/src/peer_record.rs @@ -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"; diff --git a/core/src/translation.rs b/core/src/translation.rs index 70700ca6ae8..efddae31052 100644 --- a/core/src/translation.rs +++ b/core/src/translation.rs @@ -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(), diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index bf88215dd43..6e4b9322ee5 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -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; diff --git a/core/src/upgrade/apply.rs b/core/src/upgrade/apply.rs index 15cb0348cf3..f84aaaac9fa 100644 --- a/core/src/upgrade/apply.rs +++ b/core/src/upgrade/apply.rs @@ -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; diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 3fb25aa6222..def66c4823b 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -110,22 +110,3 @@ impl Behaviour { } } } - -#[derive(Debug)] -#[allow(clippy::large_enum_variant)] -enum Event { - AutoNat(autonat::Event), - Identify(identify::Event), -} - -impl From for Event { - fn from(v: identify::Event) -> Self { - Self::Identify(v) - } -} - -impl From for Event { - fn from(v: autonat::Event) -> Self { - Self::AutoNat(v) - } -} diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index 44a53f0d17f..389cc0fa26f 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -94,22 +94,3 @@ impl Behaviour { } } } - -#[derive(Debug)] -#[allow(clippy::large_enum_variant)] -enum Event { - AutoNat(autonat::Event), - Identify(identify::Event), -} - -impl From for Event { - fn from(v: identify::Event) -> Self { - Self::Identify(v) - } -} - -impl From for Event { - fn from(v: autonat::Event) -> Self { - Self::AutoNat(v) - } -} diff --git a/identity/src/ed25519.rs b/identity/src/ed25519.rs index 529a4dddea1..d77c44547d6 100644 --- a/identity/src/ed25519.rs +++ b/identity/src/ed25519.rs @@ -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. diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index bdfb68c0091..f1e8a7c2142 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -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; diff --git a/identity/src/lib.rs b/identity/src/lib.rs index c78e68d1652..4f4313e8f17 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -34,7 +34,7 @@ //! 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", @@ -42,7 +42,6 @@ feature = "rsa" ))] mod proto { - #![allow(unreachable_pub)] include!("generated/mod.rs"); pub(crate) use self::keys_proto::*; } diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 1d85fe66ffa..7b3f799f612 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -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. diff --git a/misc/metrics/src/identify.rs b/misc/metrics/src/identify.rs index b1d4e9f0c89..03ac3f9634e 100644 --- a/misc/metrics/src/identify.rs +++ b/misc/metrics/src/identify.rs @@ -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; @@ -138,11 +138,6 @@ impl super::Recorder> for Metrics { } } -#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)] -struct AddressLabels { - protocols: String, -} - #[derive(Default, Debug, Clone)] struct Peers(Arc>>); diff --git a/misc/multistream-select/src/listener_select.rs b/misc/multistream-select/src/listener_select.rs index 21c507096e2..b4236310a1d 100644 --- a/misc/multistream-select/src/listener_select.rs +++ b/misc/multistream-select/src/listener_select.rs @@ -28,7 +28,6 @@ use futures::prelude::*; use smallvec::SmallVec; use std::{ convert::TryFrom as _, - iter::FromIterator, mem, pin::Pin, task::{Context, Poll}, diff --git a/misc/multistream-select/src/protocol.rs b/misc/multistream-select/src/protocol.rs index aef9f16c4cf..2189c50e697 100644 --- a/misc/multistream-select/src/protocol.rs +++ b/misc/multistream-select/src/protocol.rs @@ -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, diff --git a/misc/quick-protobuf-codec/src/lib.rs b/misc/quick-protobuf-codec/src/lib.rs index c50b1264af6..166ee82ff08 100644 --- a/misc/quick-protobuf-codec/src/lib.rs +++ b/misc/quick-protobuf-codec/src/lib.rs @@ -182,7 +182,6 @@ impl From for io::Error { #[cfg(test)] mod tests { use super::*; - use crate::proto; use asynchronous_codec::FramedRead; use futures::io::Cursor; use futures::{FutureExt, StreamExt}; diff --git a/misc/rw-stream-sink/src/lib.rs b/misc/rw-stream-sink/src/lib.rs index ee05196bfb4..f10e683ad33 100644 --- a/misc/rw-stream-sink/src/lib.rs +++ b/misc/rw-stream-sink/src/lib.rs @@ -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}, diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index c67e0e3baec..17ca9ad46f6 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -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; diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 2b5eb52a11e..bcfeb62fccf 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -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; diff --git a/protocols/autonat/src/protocol.rs b/protocols/autonat/src/protocol.rs index c1862058400..2ce538fddf4 100644 --- a/protocols/autonat/src/protocol.rs +++ b/protocols/autonat/src/protocol.rs @@ -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"); @@ -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 diff --git a/protocols/dcutr/src/behaviour.rs b/protocols/dcutr/src/behaviour.rs index 3742eb512f5..4409b5f6a64 100644 --- a/protocols/dcutr/src/behaviour.rs +++ b/protocols/dcutr/src/behaviour.rs @@ -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" ); diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index b8f90daf3a1..005d8394f5e 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -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; diff --git a/protocols/dcutr/src/protocol/outbound.rs b/protocols/dcutr/src/protocol/outbound.rs index d9cb60a01f6..dc46442fae5 100644 --- a/protocols/dcutr/src/protocol/outbound.rs +++ b/protocols/dcutr/src/protocol/outbound.rs @@ -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; diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 24a32de4cc7..f2515c3c564 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -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); } @@ -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); diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 2bf1c90c5c8..1a63b52541f 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -22,17 +22,12 @@ use super::*; use crate::subscription_filter::WhitelistSubscriptionFilter; -use crate::transform::{DataTransform, IdentityTransform}; -use crate::ValidationError; -use crate::{ - config::Config, config::ConfigBuilder, types::Rpc, IdentTopic as Topic, TopicScoreParams, -}; +use crate::{config::ConfigBuilder, types::Rpc, IdentTopic as Topic}; use async_std::net::Ipv4Addr; use byteorder::{BigEndian, ByteOrder}; -use libp2p_core::{ConnectedPoint, Endpoint}; +use libp2p_core::ConnectedPoint; use rand::Rng; use std::thread::sleep; -use std::time::Duration; #[derive(Default, Debug)] struct InjectNodes @@ -396,7 +391,7 @@ fn test_subscribe() { .create_network(); assert!( - gs.mesh.get(&topic_hashes[0]).is_some(), + gs.mesh.contains_key(&topic_hashes[0]), "Subscribe should add a new entry to the mesh[topic] hashmap" ); @@ -442,11 +437,11 @@ fn test_unsubscribe() { for topic_hash in &topic_hashes { assert!( - gs.topic_peers.get(topic_hash).is_some(), + gs.topic_peers.contains_key(topic_hash), "Topic_peers contain a topic entry" ); assert!( - gs.mesh.get(topic_hash).is_some(), + gs.mesh.contains_key(topic_hash), "mesh should contain a topic entry" ); } @@ -479,7 +474,7 @@ fn test_unsubscribe() { // check we clean up internal structures for topic_hash in &topic_hashes { assert!( - gs.mesh.get(topic_hash).is_none(), + !gs.mesh.contains_key(topic_hash), "All topics should have been removed from the mesh" ); } @@ -624,7 +619,7 @@ fn test_publish_without_flood_publishing() { .create_network(); assert!( - gs.mesh.get(&topic_hashes[0]).is_some(), + gs.mesh.contains_key(&topic_hashes[0]), "Subscribe should add a new entry to the mesh[topic] hashmap" ); @@ -703,7 +698,7 @@ fn test_fanout() { .create_network(); assert!( - gs.mesh.get(&topic_hashes[0]).is_some(), + gs.mesh.contains_key(&topic_hashes[0]), "Subscribe should add a new entry to the mesh[topic] hashmap" ); // Unsubscribe from topic @@ -873,7 +868,7 @@ fn test_handle_received_subscriptions() { ); assert!( - gs.peer_topics.get(&unknown_peer).is_none(), + !gs.peer_topics.contains_key(&unknown_peer), "Unknown peer should not have been added" ); @@ -1272,7 +1267,7 @@ fn test_handle_graft_multiple_topics() { } assert!( - gs.mesh.get(&topic_hashes[2]).is_none(), + !gs.mesh.contains_key(&topic_hashes[2]), "Expected the second topic to not be in the mesh" ); } @@ -5100,7 +5095,7 @@ fn test_graft_without_subscribe() { .create_network(); assert!( - gs.mesh.get(&topic_hashes[0]).is_some(), + gs.mesh.contains_key(&topic_hashes[0]), "Subscribe should add a new entry to the mesh[topic] hashmap" ); diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 7e79912cc4a..cd2326279eb 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -860,10 +860,8 @@ impl std::fmt::Debug for Config { mod test { use super::*; use crate::topic::IdentityHash; - use crate::types::PeerKind; use crate::Topic; use libp2p_core::UpgradeInfo; - use libp2p_swarm::StreamProtocol; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index ef4a93bc936..aa65e3b7f1d 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -221,9 +221,7 @@ impl MessageCache { #[cfg(test)] mod tests { use super::*; - use crate::types::RawMessage; - use crate::{IdentTopic as Topic, TopicHash}; - use libp2p_identity::PeerId; + use crate::IdentTopic as Topic; fn gen_testm(x: u64, topic: TopicHash) -> (MessageId, RawMessage) { let default_id = |message: &RawMessage| { diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index b1ea9bfae95..386cc85bd3c 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -99,7 +99,7 @@ impl PeerStats { topic_hash: TopicHash, params: &PeerScoreParams, ) -> Option<&mut TopicStats> { - if params.topics.get(&topic_hash).is_some() { + if params.topics.contains_key(&topic_hash) { Some(self.topics.entry(topic_hash).or_default()) } else { self.topics.get_mut(&topic_hash) @@ -307,7 +307,7 @@ impl PeerScore { // P6: IP collocation factor for ip in peer_stats.known_ips.iter() { - if self.params.ip_colocation_factor_whitelist.get(ip).is_some() { + if self.params.ip_colocation_factor_whitelist.contains(ip) { continue; } @@ -680,7 +680,7 @@ impl PeerScore { ) { let record = self.deliveries.entry(msg_id.clone()).or_default(); - if record.peers.get(from).is_some() { + if record.peers.contains(from) { // we have already seen this duplicate! return; } diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index e9600a4d8d8..01a38562c02 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -29,7 +29,6 @@ use crate::ValidationError; use asynchronous_codec::{Decoder, Encoder, Framed}; use byteorder::{BigEndian, ByteOrder}; use bytes::BytesMut; -use futures::future; use futures::prelude::*; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity::{PeerId, PublicKey}; diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter.rs index 09c323d7904..02bb9b4eab6 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter.rs @@ -212,7 +212,6 @@ impl TopicSubscriptionFilter for RegexSubscriptionFilter { mod test { use super::*; use crate::types::SubscriptionAction::*; - use std::iter::FromIterator; #[test] fn test_filter_incoming_allow_all_with_duplicates() { diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index c6b22b00c0a..f4dfd544dd1 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -25,7 +25,6 @@ use libp2p_core::{multiaddr, Multiaddr}; use libp2p_identity as identity; use libp2p_identity::PublicKey; use libp2p_swarm::StreamProtocol; -use std::convert::TryFrom; use std::io; use thiserror::Error; diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index b879084c54f..7005f39e5e6 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -22,32 +22,22 @@ use super::*; -use crate::kbucket::Distance; use crate::record::{store::MemoryStore, Key}; -use crate::{K_VALUE, PROTOCOL_NAME, SHA_256_MH}; +use crate::{PROTOCOL_NAME, SHA_256_MH}; use futures::{executor::block_on, future::poll_fn, prelude::*}; use futures_timer::Delay; use libp2p_core::{ - connection::ConnectedPoint, - multiaddr::{multiaddr, Multiaddr, Protocol}, + multiaddr::{multiaddr, Protocol}, multihash::Multihash, transport::MemoryTransport, - upgrade, Endpoint, Transport, + upgrade, Transport, }; use libp2p_identity as identity; -use libp2p_identity::PeerId; use libp2p_noise as noise; -use libp2p_swarm::behaviour::ConnectionEstablished; -use libp2p_swarm::{self as swarm, ConnectionId, Swarm, SwarmEvent}; +use libp2p_swarm::{self as swarm, Swarm, SwarmEvent}; use libp2p_yamux as yamux; use quickcheck::*; use rand::{random, rngs::StdRng, thread_rng, Rng, SeedableRng}; -use std::{ - collections::{HashMap, HashSet}, - num::NonZeroUsize, - time::Duration, - u64, -}; type TestSwarm = Swarm>; diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index a0d272c31f1..cf5591c5cf6 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -75,7 +75,7 @@ mod key; pub use bucket::NodeStatus; pub use entry::*; -use arrayvec::{self, ArrayVec}; +use arrayvec::ArrayVec; use bucket::KBucket; use std::collections::VecDeque; use std::time::{Duration, Instant}; diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index d70161919e1..5e65bc15a37 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -431,7 +431,6 @@ mod tests { use super::*; use libp2p_identity::PeerId; use quickcheck::*; - use std::collections::VecDeque; impl Arbitrary for KBucket, ()> { fn arbitrary(g: &mut Gen) -> KBucket, ()> { diff --git a/protocols/kad/src/kbucket/entry.rs b/protocols/kad/src/kbucket/entry.rs index 02c90fdfcc7..d89853b1761 100644 --- a/protocols/kad/src/kbucket/entry.rs +++ b/protocols/kad/src/kbucket/entry.rs @@ -21,7 +21,7 @@ //! The `Entry` API for quering and modifying the entries of a `KBucketsTable` //! representing the nodes participating in the Kademlia DHT. -pub(crate) use super::bucket::{AppliedPending, InsertResult, Node, NodeStatus, K_VALUE}; +pub(crate) use super::bucket::{AppliedPending, InsertResult, Node, K_VALUE}; pub use super::key::*; use super::*; diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 5abe2089852..9803af00579 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -37,7 +37,7 @@ use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_swarm::StreamProtocol; use std::marker::PhantomData; -use std::{convert::TryFrom, time::Duration}; +use std::time::Duration; use std::{io, iter}; use tracing::debug; diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index dc913f1bbca..537da6a9d7d 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -23,9 +23,8 @@ use super::*; use crate::kbucket::{Distance, Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; use instant::Instant; -use libp2p_identity::PeerId; use std::collections::btree_map::{BTreeMap, Entry}; -use std::{iter::FromIterator, num::NonZeroUsize, time::Duration}; +use std::{num::NonZeroUsize, time::Duration}; pub(crate) mod disjoint; /// A peer iterator for a dynamically changing list of peers, sorted by increasing @@ -477,10 +476,9 @@ mod tests { use super::*; use crate::SHA_256_MH; use libp2p_core::multihash::Multihash; - use libp2p_identity::PeerId; use quickcheck::*; use rand::{rngs::StdRng, Rng, SeedableRng}; - use std::{iter, time::Duration}; + use std::iter; fn random_peers(n: usize, g: &mut R) -> Vec { (0..n) diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 68721f93d7c..e8309a2deda 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -19,9 +19,6 @@ // DEALINGS IN THE SOFTWARE. use super::*; -use crate::kbucket::{Key, KeyBytes}; -use instant::Instant; -use libp2p_identity::PeerId; use std::{ collections::HashMap, iter::{Cycle, Map, Peekable}, @@ -438,7 +435,7 @@ impl>> Iterator for ResultIter { mod tests { use super::*; - use crate::{K_VALUE, SHA_256_MH}; + use crate::SHA_256_MH; use libp2p_core::multihash::Multihash; use quickcheck::*; use std::collections::HashSet; @@ -602,20 +599,6 @@ mod tests { } } - #[derive(Debug, Clone)] - struct PeerVec(Vec>); - - impl Arbitrary for PeerVec { - fn arbitrary(g: &mut Gen) -> Self { - PeerVec( - (0..g.gen_range(1..60u8)) - .map(|_| ArbitraryPeerId::arbitrary(g).0) - .map(Key::from) - .collect(), - ) - } - } - #[test] fn s_kademlia_disjoint_paths() { let now = Instant::now(); diff --git a/protocols/kad/src/query/peers/fixed.rs b/protocols/kad/src/query/peers/fixed.rs index 50a969380a3..b34f7516801 100644 --- a/protocols/kad/src/query/peers/fixed.rs +++ b/protocols/kad/src/query/peers/fixed.rs @@ -21,7 +21,6 @@ use super::*; use fnv::FnvHashMap; -use libp2p_identity::PeerId; use std::{collections::hash_map::Entry, num::NonZeroUsize, vec}; /// A peer iterator for a fixed set of peers. diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index edeae188ac6..86c136ebeda 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -21,9 +21,7 @@ use super::*; use crate::kbucket; -use libp2p_identity::PeerId; use smallvec::SmallVec; -use std::borrow::Cow; use std::collections::{hash_map, hash_set, HashMap, HashSet}; use std::iter; @@ -217,7 +215,6 @@ impl RecordStore for MemoryStore { mod tests { use super::*; use crate::SHA_256_MH; - use libp2p_core::multihash::Multihash; use quickcheck::*; use rand::Rng; diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 6cc5550dbe5..41ce9efa714 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -397,7 +397,6 @@ mod tests { use super::*; use hickory_proto::op::Message; use libp2p_identity as identity; - use std::time::Duration; #[test] fn build_query_correct() { diff --git a/protocols/mdns/src/behaviour/socket.rs b/protocols/mdns/src/behaviour/socket.rs index fa9e0fbaf1e..ebaad17e45f 100644 --- a/protocols/mdns/src/behaviour/socket.rs +++ b/protocols/mdns/src/behaviour/socket.rs @@ -20,7 +20,6 @@ use std::{ io::Error, - marker::Unpin, net::{SocketAddr, UdpSocket}, task::{Context, Poll}, }; diff --git a/protocols/mdns/src/behaviour/timer.rs b/protocols/mdns/src/behaviour/timer.rs index 29622be9a38..4f6ceec306d 100644 --- a/protocols/mdns/src/behaviour/timer.rs +++ b/protocols/mdns/src/behaviour/timer.rs @@ -18,10 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std::{ - marker::Unpin, - time::{Duration, Instant}, -}; +use std::time::{Duration, Instant}; /// Simple wrapper for the different type of timers #[derive(Debug)] diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 28549e1c198..fe84cb4ea59 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -89,8 +89,6 @@ mod tests { multiaddr::multiaddr, transport::{memory::MemoryTransport, ListenerId, Transport}, }; - use rand::{thread_rng, Rng}; - use std::time::Duration; #[test] fn ping_pong() { diff --git a/protocols/relay/src/behaviour/rate_limiter.rs b/protocols/relay/src/behaviour/rate_limiter.rs index 9c4f67d04a8..73c164c121c 100644 --- a/protocols/relay/src/behaviour/rate_limiter.rs +++ b/protocols/relay/src/behaviour/rate_limiter.rs @@ -22,7 +22,6 @@ use instant::Instant; use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_identity::PeerId; use std::collections::{HashMap, VecDeque}; -use std::convert::TryInto; use std::hash::Hash; use std::net::IpAddr; use std::num::NonZeroU32; @@ -173,7 +172,6 @@ impl GenericRateLimiter { mod tests { use super::*; use quickcheck::{QuickCheck, TestResult}; - use std::num::NonZeroU32; #[test] fn first() { diff --git a/protocols/relay/src/copy_future.rs b/protocols/relay/src/copy_future.rs index 755344cd698..91415065d2c 100644 --- a/protocols/relay/src/copy_future.rs +++ b/protocols/relay/src/copy_future.rs @@ -30,7 +30,6 @@ use futures::io::{AsyncBufRead, BufReader}; use futures::io::{AsyncRead, AsyncWrite}; use futures::ready; use futures_timer::Delay; -use std::convert::TryInto; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; @@ -164,12 +163,9 @@ fn forward_data( mod tests { use super::*; use futures::executor::block_on; - use futures::io::{AsyncRead, AsyncWrite, BufReader, BufWriter}; + use futures::io::BufWriter; use quickcheck::QuickCheck; use std::io::ErrorKind; - use std::pin::Pin; - use std::task::{Context, Poll}; - use std::time::Duration; #[test] fn quickcheck() { diff --git a/protocols/rendezvous/src/codec.rs b/protocols/rendezvous/src/codec.rs index 41432a91d8c..cad3688e00b 100644 --- a/protocols/rendezvous/src/codec.rs +++ b/protocols/rendezvous/src/codec.rs @@ -27,7 +27,6 @@ use libp2p_core::{peer_record, signed_envelope, PeerRecord, SignedEnvelope}; use libp2p_swarm::StreamProtocol; use quick_protobuf_codec::Codec as ProtobufCodec; use rand::RngCore; -use std::convert::{TryFrom, TryInto}; use std::{fmt, io}; pub type Ttl = u64; @@ -642,7 +641,6 @@ mod proto { #[cfg(test)] mod tests { use super::*; - use crate::Namespace; #[test] fn cookie_wire_encoding_roundtrip() { diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 667c71e20e3..0ed1b6523d1 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -34,7 +34,6 @@ use libp2p_swarm::{ }; use std::collections::{HashMap, HashSet}; use std::iter; -use std::iter::FromIterator; use std::task::{ready, Context, Poll}; use std::time::Duration; @@ -529,7 +528,6 @@ pub struct CookieNamespaceMismatch; #[cfg(test)] mod tests { use instant::SystemTime; - use std::option::Option::None; use libp2p_core::PeerRecord; use libp2p_identity as identity; diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index c2de88fd615..d9200780ece 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -27,7 +27,6 @@ use libp2p_rendezvous as rendezvous; use libp2p_rendezvous::client::RegisterError; use libp2p_swarm::{DialError, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; -use std::convert::TryInto; use std::time::Duration; use tracing_subscriber::EnvFilter; diff --git a/protocols/request-response/src/cbor.rs b/protocols/request-response/src/cbor.rs index f371f6149dc..44d82be2630 100644 --- a/protocols/request-response/src/cbor.rs +++ b/protocols/request-response/src/cbor.rs @@ -47,7 +47,6 @@ mod codec { use async_trait::async_trait; use cbor4ii::core::error::DecodeError; use futures::prelude::*; - use futures::{AsyncRead, AsyncWrite}; use libp2p_swarm::StreamProtocol; use serde::{de::DeserializeOwned, Serialize}; use std::{collections::TryReserveError, convert::Infallible, io, marker::PhantomData}; diff --git a/protocols/request-response/src/json.rs b/protocols/request-response/src/json.rs index 0b3d634573b..85e78e7ddda 100644 --- a/protocols/request-response/src/json.rs +++ b/protocols/request-response/src/json.rs @@ -45,7 +45,6 @@ pub type Behaviour = crate::Behaviour>; mod codec { use async_trait::async_trait; use futures::prelude::*; - use futures::{AsyncRead, AsyncWrite}; use libp2p_swarm::StreamProtocol; use serde::{de::DeserializeOwned, Serialize}; use std::{io, marker::PhantomData}; diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index b9e7878a78b..827afae249c 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -26,7 +26,7 @@ use libp2p_request_response as request_response; use libp2p_request_response::ProtocolSupport; use libp2p_swarm::{StreamProtocol, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; -use rand::{self, Rng}; +use rand::Rng; use serde::{Deserialize, Serialize}; use std::{io, iter}; use tracing_subscriber::EnvFilter; diff --git a/swarm/src/behaviour/peer_addresses.rs b/swarm/src/behaviour/peer_addresses.rs index a011867dcdf..1eeead56ca1 100644 --- a/swarm/src/behaviour/peer_addresses.rs +++ b/swarm/src/behaviour/peer_addresses.rs @@ -101,7 +101,7 @@ mod tests { use super::*; use std::io; - use crate::{ConnectionId, DialError}; + use crate::ConnectionId; use libp2p_core::{ multiaddr::Protocol, transport::{memory::MemoryTransportError, TransportError}, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 15c49bb7bd5..a6e8e1c6851 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -373,7 +373,7 @@ where match shutdown { Shutdown::None => {} Shutdown::Asap => return Poll::Ready(Err(ConnectionError::KeepAliveTimeout)), - Shutdown::Later(delay, _) => match Future::poll(Pin::new(delay), cx) { + Shutdown::Later(delay) => match Future::poll(Pin::new(delay), cx) { Poll::Ready(_) => { return Poll::Ready(Err(ConnectionError::KeepAliveTimeout)) } @@ -470,15 +470,12 @@ fn compute_new_shutdown( ) -> Option { match (current_shutdown, handler_keep_alive) { (_, false) if idle_timeout == Duration::ZERO => Some(Shutdown::Asap), - (Shutdown::Later(_, _), false) => None, // Do nothing, i.e. let the shutdown timer continue to tick. + (Shutdown::Later(_), false) => None, // Do nothing, i.e. let the shutdown timer continue to tick. (_, false) => { let now = Instant::now(); let safe_keep_alive = checked_add_fraction(now, idle_timeout); - Some(Shutdown::Later( - Delay::new(safe_keep_alive), - now + safe_keep_alive, - )) + Some(Shutdown::Later(Delay::new(safe_keep_alive))) } (_, true) => Some(Shutdown::None), } @@ -734,7 +731,7 @@ enum Shutdown { /// A shut down is planned as soon as possible. Asap, /// A shut down is planned for when a `Delay` has elapsed. - Later(Delay, Instant), + Later(Delay), } #[cfg(test)] @@ -947,11 +944,10 @@ mod tests { let shutdown = match self.0 { Shutdown::None => Shutdown::None, Shutdown::Asap => Shutdown::Asap, - Shutdown::Later(_, instant) => Shutdown::Later( + Shutdown::Later(_) => Shutdown::Later( // compute_new_shutdown does not touch the delay. Delay does not // implement Clone. Thus use a placeholder delay. Delay::new(Duration::from_secs(1)), - instant, ), }; @@ -964,12 +960,7 @@ mod tests { let shutdown = match g.gen_range(1u8..4) { 1 => Shutdown::None, 2 => Shutdown::Asap, - 3 => Shutdown::Later( - Delay::new(Duration::from_secs(u32::arbitrary(g) as u64)), - Instant::now() - .checked_add(Duration::arbitrary(g)) - .unwrap_or(Instant::now()), - ), + 3 => Shutdown::Later(Delay::new(Duration::from_secs(u32::arbitrary(g) as u64))), _ => unreachable!(), }; @@ -1000,7 +991,9 @@ mod tests { self: Pin<&mut Self>, _: &mut Context<'_>, ) -> Poll> { - Poll::Ready(Ok(PendingSubstream(Arc::downgrade(&self.counter)))) + Poll::Ready(Ok(PendingSubstream { + _weak: Arc::downgrade(&self.counter), + })) } fn poll_outbound( @@ -1055,7 +1048,9 @@ mod tests { } } - struct PendingSubstream(Weak<()>); + struct PendingSubstream { + _weak: Weak<()>, + } impl AsyncRead for PendingSubstream { fn poll_read( diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 9bcd1b446d3..f876c39f12c 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -42,7 +42,7 @@ use libp2p_core::connection::Endpoint; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt}; use std::task::Waker; use std::{ - collections::{hash_map, HashMap}, + collections::HashMap, fmt, num::{NonZeroU8, NonZeroUsize}, pin::Pin, @@ -1029,28 +1029,3 @@ impl PoolConfig { self } } - -trait EntryExt<'a, K, V> { - fn expect_occupied(self, msg: &'static str) -> hash_map::OccupiedEntry<'a, K, V>; -} - -impl<'a, K: 'a, V: 'a> EntryExt<'a, K, V> for hash_map::Entry<'a, K, V> { - fn expect_occupied(self, msg: &'static str) -> hash_map::OccupiedEntry<'a, K, V> { - match self { - hash_map::Entry::Occupied(entry) => entry, - hash_map::Entry::Vacant(_) => panic!("{}", msg), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use futures::future::Future; - - struct Dummy; - - impl Executor for Dummy { - fn exec(&self, _: Pin + Send>>) {} - } -} diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 96a77626c01..5efcde5c2bb 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -35,7 +35,7 @@ use std::{ error, fmt::{self, Debug}, hash::Hash, - iter::{self, FromIterator}, + iter, task::{Context, Poll}, time::Duration, }; diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index b1fc41e9098..fc1074b31e4 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -232,6 +232,6 @@ mod tests { } })); - assert!(matches!(handler.connection_keep_alive(), false)); + assert!(!handler.connection_keep_alive()); } } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 2f02e43348d..dac380855aa 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -146,7 +146,6 @@ use std::collections::{HashMap, HashSet, VecDeque}; use std::num::{NonZeroU32, NonZeroU8, NonZeroUsize}; use std::time::Duration; use std::{ - convert::TryFrom, error, fmt, io, pin::Pin, task::{Context, Poll}, @@ -1771,14 +1770,10 @@ impl NetworkInfo { #[cfg(test)] mod tests { use super::*; - use crate::dummy; use crate::test::{CallTraceBehaviour, MockBehaviour}; - use futures::future; use libp2p_core::multiaddr::multiaddr; use libp2p_core::transport::memory::MemoryTransportError; - use libp2p_core::transport::TransportEvent; - use libp2p_core::Endpoint; - use libp2p_core::{multiaddr, transport, upgrade}; + use libp2p_core::{multiaddr, upgrade}; use libp2p_identity as identity; use libp2p_plaintext as plaintext; use libp2p_yamux as yamux; @@ -1832,7 +1827,7 @@ mod tests { && swarm2.is_connected(swarm1.local_peer_id()) } - fn swarms_disconnected( + fn swarms_disconnected( swarm1: &Swarm>, swarm2: &Swarm>, ) -> bool diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 707abb03d6e..12f0d0a5ba8 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -133,19 +133,19 @@ fn custom_event() { #[allow(clippy::large_enum_variant)] enum MyEvent { - Ping(ping::Event), - Identify(identify::Event), + Ping, + Identify, } impl From for MyEvent { - fn from(event: ping::Event) -> Self { - MyEvent::Ping(event) + fn from(_event: ping::Event) -> Self { + MyEvent::Ping } } impl From for MyEvent { - fn from(event: identify::Event) -> Self { - MyEvent::Identify(event) + fn from(_event: identify::Event) -> Self { + MyEvent::Identify } } @@ -167,19 +167,19 @@ fn custom_event_mismatching_field_names() { #[allow(clippy::large_enum_variant)] enum MyEvent { - Ping(ping::Event), - Identify(identify::Event), + Ping, + Identify, } impl From for MyEvent { - fn from(event: ping::Event) -> Self { - MyEvent::Ping(event) + fn from(_event: ping::Event) -> Self { + MyEvent::Ping } } impl From for MyEvent { - fn from(event: identify::Event) -> Self { - MyEvent::Identify(event) + fn from(_event: identify::Event) -> Self { + MyEvent::Identify } } @@ -252,19 +252,19 @@ fn nested_derives_with_import() { fn custom_event_emit_event_through_poll() { #[allow(clippy::large_enum_variant)] enum BehaviourOutEvent { - Ping(ping::Event), - Identify(identify::Event), + Ping, + Identify, } impl From for BehaviourOutEvent { - fn from(event: ping::Event) -> Self { - BehaviourOutEvent::Ping(event) + fn from(_event: ping::Event) -> Self { + BehaviourOutEvent::Ping } } impl From for BehaviourOutEvent { - fn from(event: identify::Event) -> Self { - BehaviourOutEvent::Identify(event) + fn from(_event: identify::Event) -> Self { + BehaviourOutEvent::Identify } } @@ -293,8 +293,8 @@ fn custom_event_emit_event_through_poll() { // check that the event is bubbled up all the way to swarm loop { match _swarm.select_next_some().await { - SwarmEvent::Behaviour(BehaviourOutEvent::Ping(_)) => break, - SwarmEvent::Behaviour(BehaviourOutEvent::Identify(_)) => break, + SwarmEvent::Behaviour(BehaviourOutEvent::Ping) => break, + SwarmEvent::Behaviour(BehaviourOutEvent::Identify) => break, _ => {} } } @@ -460,21 +460,20 @@ fn with_generics_constrained() { fn custom_event_with_either() { use either::Either; - #[allow(clippy::large_enum_variant)] enum BehaviourOutEvent { - Kad(libp2p_kad::Event), - PingOrIdentify(Either), + Kad, + PingOrIdentify, } impl From for BehaviourOutEvent { - fn from(event: libp2p_kad::Event) -> Self { - BehaviourOutEvent::Kad(event) + fn from(_event: libp2p_kad::Event) -> Self { + BehaviourOutEvent::Kad } } impl From> for BehaviourOutEvent { - fn from(event: Either) -> Self { - BehaviourOutEvent::PingOrIdentify(event) + fn from(_event: Either) -> Self { + BehaviourOutEvent::PingOrIdentify } } diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index be847e568ed..a0fdaf53bdf 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -157,7 +157,6 @@ use smallvec::SmallVec; use std::io; use std::net::{Ipv4Addr, Ipv6Addr}; use std::{ - convert::TryFrom, error, fmt, iter, ops::DerefMut, pin::Pin, @@ -628,12 +627,7 @@ where #[cfg(all(test, any(feature = "tokio", feature = "async-std")))] mod tests { use super::*; - use futures::future::BoxFuture; - use libp2p_core::{ - multiaddr::{Multiaddr, Protocol}, - transport::{TransportError, TransportEvent}, - Transport, - }; + use libp2p_core::Transport; use libp2p_identity::PeerId; #[test] diff --git a/transports/noise/src/io/handshake.rs b/transports/noise/src/io/handshake.rs index 7cc0f859e6e..5c1fa806b6d 100644 --- a/transports/noise/src/io/handshake.rs +++ b/transports/noise/src/io/handshake.rs @@ -248,7 +248,7 @@ where ..Default::default() }; - pb.identity_sig = state.identity.signature.clone(); + pb.identity_sig.clone_from(&state.identity.signature); // If this is the responder then send WebTransport certhashes to initiator, if any. if state.io.codec().is_responder() { diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index e37c55c7f10..29d0c81e2e4 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -292,8 +292,6 @@ impl snow::types::Dh for Keypair { #[cfg(test)] mod tests { use super::*; - use crate::protocol::PARAMS_XX; - use once_cell::sync::Lazy; #[test] fn handshake_hashes_disagree_if_prologue_differs() { diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 7100e7c7a8d..62b5d41d6b9 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -25,7 +25,7 @@ use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; use quickcheck::*; -use std::{convert::TryInto, io}; +use std::io; use tracing_subscriber::EnvFilter; #[allow(dead_code)] diff --git a/transports/quic/src/transport.rs b/transports/quic/src/transport.rs index aea3c91093f..c33931fc798 100644 --- a/transports/quic/src/transport.rs +++ b/transports/quic/src/transport.rs @@ -754,10 +754,8 @@ fn socketaddr_to_multiaddr(socket_addr: &SocketAddr, version: ProtocolVersion) - #[cfg(test)] #[cfg(any(feature = "async-std", feature = "tokio"))] mod tests { - use futures::future::poll_fn; - use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - use super::*; + use futures::future::poll_fn; #[test] fn multiaddr_to_udp_conversion() { diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index fbb7008aa5b..c8f0410d9e5 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -36,11 +36,7 @@ pub use provider::async_io; #[cfg(feature = "tokio")] pub use provider::tokio; -use futures::{ - future::{self, Ready}, - prelude::*, - stream::SelectAll, -}; +use futures::{future::Ready, prelude::*, stream::SelectAll}; use futures_timer::Delay; use if_watch::IfEvent; use libp2p_core::{ diff --git a/transports/tcp/src/provider/tokio.rs b/transports/tcp/src/provider/tokio.rs index b991c6bdae1..ec2d098e3fb 100644 --- a/transports/tcp/src/provider/tokio.rs +++ b/transports/tcp/src/provider/tokio.rs @@ -24,7 +24,6 @@ use futures::{ future::{BoxFuture, FutureExt}, prelude::*, }; -use std::convert::TryFrom; use std::io; use std::net; use std::pin::Pin; diff --git a/transports/uds/src/lib.rs b/transports/uds/src/lib.rs index 075cbadb80a..4b1c7a1670d 100644 --- a/transports/uds/src/lib.rs +++ b/transports/uds/src/lib.rs @@ -263,7 +263,7 @@ mod tests { transport::ListenerId, Transport, }; - use std::{self, borrow::Cow, path::Path}; + use std::{borrow::Cow, path::Path}; #[test] fn multiaddr_to_path_conversion() { diff --git a/transports/webrtc-websys/src/stream/poll_data_channel.rs b/transports/webrtc-websys/src/stream/poll_data_channel.rs index 0ee4f7920c9..f323d542eaf 100644 --- a/transports/webrtc-websys/src/stream/poll_data_channel.rs +++ b/transports/webrtc-websys/src/stream/poll_data_channel.rs @@ -10,7 +10,7 @@ use bytes::BytesMut; use futures::task::AtomicWaker; use futures::{AsyncRead, AsyncWrite}; use libp2p_webrtc_utils::MAX_MSG_LEN; -use wasm_bindgen::{prelude::*, JsCast}; +use wasm_bindgen::prelude::*; use web_sys::{Event, MessageEvent, RtcDataChannel, RtcDataChannelEvent, RtcDataChannelState}; /// [`PollDataChannel`] is a wrapper around around [`RtcDataChannel`] which implements [`AsyncRead`] and [`AsyncWrite`]. diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 02cfa6f7296..2e73ac9c459 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use futures::{future::BoxFuture, prelude::*, stream::SelectAll, stream::Stream}; +use futures::{future::BoxFuture, prelude::*, stream::SelectAll}; use if_watch::{tokio::IfWatcher, IfEvent}; use libp2p_core::{ multiaddr::{Multiaddr, Protocol}, @@ -431,9 +431,9 @@ fn parse_webrtc_listen_addr(addr: &Multiaddr) -> Option { mod tests { use super::*; use futures::future::poll_fn; - use libp2p_core::{multiaddr::Protocol, Transport as _}; + use libp2p_core::Transport as _; use rand::thread_rng; - use std::net::{IpAddr, Ipv6Addr}; + use std::net::Ipv6Addr; #[test] fn missing_webrtc_protocol() { diff --git a/transports/websocket-websys/src/lib.rs b/transports/websocket-websys/src/lib.rs index 5c1a6ebf1c4..02b6bc837eb 100644 --- a/transports/websocket-websys/src/lib.rs +++ b/transports/websocket-websys/src/lib.rs @@ -36,7 +36,7 @@ use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use std::{pin::Pin, task::Context, task::Poll}; -use wasm_bindgen::{prelude::*, JsCast}; +use wasm_bindgen::prelude::*; use web_sys::{CloseEvent, Event, MessageEvent, WebSocket}; use crate::web_context::WebContext; diff --git a/transports/websocket-websys/src/web_context.rs b/transports/websocket-websys/src/web_context.rs index c514435d2bb..2b5d7b46431 100644 --- a/transports/websocket-websys/src/web_context.rs +++ b/transports/websocket-websys/src/web_context.rs @@ -1,4 +1,4 @@ -use wasm_bindgen::{prelude::*, JsCast}; +use wasm_bindgen::prelude::*; use web_sys::window; /// Web context that abstract the window vs web worker API diff --git a/transports/websocket/src/framed.rs b/transports/websocket/src/framed.rs index 3593e1eaff2..584bb2b5058 100644 --- a/transports/websocket/src/framed.rs +++ b/transports/websocket/src/framed.rs @@ -34,7 +34,7 @@ use soketto::{ handshake, }; use std::{collections::HashMap, ops::DerefMut, sync::Arc}; -use std::{convert::TryInto, fmt, io, mem, pin::Pin, task::Context, task::Poll}; +use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll}; use url::Url; /// Max. number of payload bytes of a single frame. diff --git a/transports/websocket/src/quicksink.rs b/transports/websocket/src/quicksink.rs index d9edb4dfe0d..cb2c98b078f 100644 --- a/transports/websocket/src/quicksink.rs +++ b/transports/websocket/src/quicksink.rs @@ -294,7 +294,7 @@ where mod tests { use crate::quicksink::{make_sink, Action}; use async_std::{io, task}; - use futures::{channel::mpsc, prelude::*, stream}; + use futures::{channel::mpsc, prelude::*}; #[test] fn smoke_test() { diff --git a/transports/websocket/src/tls.rs b/transports/websocket/src/tls.rs index 5bff818f34c..24b0df97db3 100644 --- a/transports/websocket/src/tls.rs +++ b/transports/websocket/src/tls.rs @@ -19,7 +19,6 @@ // DEALINGS IN THE SOFTWARE. use futures_rustls::{rustls, TlsAcceptor, TlsConnector}; -use std::convert::TryFrom; use std::{fmt, io, sync::Arc}; /// TLS configuration.