Skip to content

Commit

Permalink
*: Fix clippy warnings (#2615)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Apr 19, 2022
1 parent 0c1ac78 commit 22fbce3
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/src/identity/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl DerDecodable<'_> for Asn1SubjectPublicKey {
)));
}

let pk_der: Vec<u8> = object.value().into_iter().skip(1).cloned().collect();
let pk_der: Vec<u8> = object.value().iter().skip(1).cloned().collect();
// We don't parse pk_der further as an ASN.1 RsaPublicKey, since
// we only need the DER encoding for `verify`.
Ok(Self(PublicKey(pk_der)))
Expand Down
2 changes: 1 addition & 1 deletion core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl PeerId {
/// In case the given [`Multiaddr`] ends with `/p2p/<peer-id>`, this function
/// will return the encapsulated [`PeerId`], otherwise it will return `None`.
pub fn try_from_multiaddr(address: &Multiaddr) -> Option<PeerId> {
address.iter().last().map_or(None, |p| match p {
address.iter().last().and_then(|p| match p {
Protocol::P2p(hash) => PeerId::from_multihash(hash).ok(),
_ => None,
})
Expand Down
2 changes: 1 addition & 1 deletion core/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl PeerRecord {
};

let envelope = SignedEnvelope::new(
&key,
key,
String::from(DOMAIN_SEP),
PAYLOAD_TYPE.as_bytes().to_vec(),
payload,
Expand Down
6 changes: 3 additions & 3 deletions core/src/transport/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ impl<T> Sink<T> for Chan<T> {
}
}

impl<T: AsRef<[u8]>> Into<RwStreamSink<Chan<T>>> for Chan<T> {
fn into(self) -> RwStreamSink<Chan<T>> {
RwStreamSink::new(self)
impl<T: AsRef<[u8]>> From<Chan<T>> for RwStreamSink<Chan<T>> {
fn from(channel: Chan<T>) -> RwStreamSink<Chan<T>> {
RwStreamSink::new(channel)
}
}

Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use crate::codec::MAX_FRAME_SIZE;
use std::cmp;

pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &'static [u8] = b"/mplex/6.7.0";
pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &[u8] = b"/mplex/6.7.0";

/// Configuration for the multiplexer.
#[derive(Debug, Clone)]
Expand Down
8 changes: 4 additions & 4 deletions muxers/mplex/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ where

/// Checks whether a substream is open for reading.
fn can_read(&self, id: &LocalStreamId) -> bool {
match self.substreams.get(id) {
Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. }) => true,
_ => false,
}
matches!(
self.substreams.get(id),
Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. })
)
}

/// Sends pending frames, without flushing.
Expand Down
14 changes: 8 additions & 6 deletions muxers/yamux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,19 @@ impl YamuxConfig {
/// Creates a new `YamuxConfig` in client mode, regardless of whether
/// it will be used for an inbound or outbound upgrade.
pub fn client() -> Self {
let mut cfg = Self::default();
cfg.mode = Some(yamux::Mode::Client);
cfg
Self {
mode: Some(yamux::Mode::Client),
..Default::default()
}
}

/// Creates a new `YamuxConfig` in server mode, regardless of whether
/// it will be used for an inbound or outbound upgrade.
pub fn server() -> Self {
let mut cfg = Self::default();
cfg.mode = Some(yamux::Mode::Server);
cfg
Self {
mode: Some(yamux::Mode::Server),
..Default::default()
}
}

/// Sets the size (in bytes) of the receive window per substream.
Expand Down
8 changes: 4 additions & 4 deletions swarm/src/behaviour/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ where
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
let event = match self {
Either::Left(behaviour) => futures::ready!(behaviour.poll(cx, params))
.map_out(|e| Either::Left(e))
.map_handler_and_in(|h| IntoEitherHandler::Left(h), |e| Either::Left(e)),
.map_out(Either::Left)
.map_handler_and_in(IntoEitherHandler::Left, Either::Left),
Either::Right(behaviour) => futures::ready!(behaviour.poll(cx, params))
.map_out(|e| Either::Right(e))
.map_handler_and_in(|h| IntoEitherHandler::Right(h), |e| Either::Right(e)),
.map_out(Either::Right)
.map_handler_and_in(IntoEitherHandler::Right, Either::Right),
};

Poll::Ready(event)
Expand Down
6 changes: 3 additions & 3 deletions swarm/src/connection/pool/concurrent_dial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where
let mut pending_dials = pending_dials.into_iter();

let dials = FuturesUnordered::new();
while let Some(dial) = pending_dials.next() {
for dial in pending_dials.by_ref() {
dials.push(dial);
if dials.len() == concurrency_factor.get() as usize {
break;
Expand Down Expand Up @@ -95,7 +95,7 @@ where
loop {
match ready!(self.dials.poll_next_unpin(cx)) {
Some((addr, Ok(output))) => {
let errors = std::mem::replace(&mut self.errors, vec![]);
let errors = std::mem::take(&mut self.errors);
return Poll::Ready(Ok((addr, output, errors)));
}
Some((addr, Err(e))) => {
Expand All @@ -105,7 +105,7 @@ where
}
}
None => {
return Poll::Ready(Err(std::mem::replace(&mut self.errors, vec![])));
return Poll::Ready(Err(std::mem::take(&mut self.errors)));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ where
};
match dial {
Ok(fut) => fut
.map(|r| (address, r.map_err(|e| TransportError::Other(e))))
.map(|r| (address, r.map_err(TransportError::Other)))
.boxed(),
Err(err) => futures::future::ready((address, Err(err))).boxed(),
}
Expand All @@ -538,7 +538,7 @@ where
Err((connection_limit, handler)) => {
let error = DialError::ConnectionLimit(connection_limit);
self.behaviour.inject_dial_failure(None, handler, &error);
return Err(error);
Err(error)
}
}
}
Expand Down Expand Up @@ -800,7 +800,7 @@ where
.expect("n + 1 is always non-zero; qed");
let non_banned_established = other_established_connection_ids
.into_iter()
.filter(|conn_id| !this.banned_peer_connections.contains(&conn_id))
.filter(|conn_id| !this.banned_peer_connections.contains(conn_id))
.count();

log::debug!(
Expand Down Expand Up @@ -896,7 +896,7 @@ where
if conn_was_reported {
let remaining_non_banned = remaining_established_connection_ids
.into_iter()
.filter(|conn_id| !this.banned_peer_connections.contains(&conn_id))
.filter(|conn_id| !this.banned_peer_connections.contains(conn_id))
.count();
this.behaviour.inject_connection_closed(
&peer_id,
Expand Down
14 changes: 8 additions & 6 deletions transports/dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ where
// dialing attempts as soon as there is another fully resolved
// address.
while let Some(addr) = unresolved.pop() {
if let Some((i, name)) = addr.iter().enumerate().find(|(_, p)| match p {
Protocol::Dns(_)
| Protocol::Dns4(_)
| Protocol::Dns6(_)
| Protocol::Dnsaddr(_) => true,
_ => false,
if let Some((i, name)) = addr.iter().enumerate().find(|(_, p)| {
matches!(
p,
Protocol::Dns(_)
| Protocol::Dns4(_)
| Protocol::Dns6(_)
| Protocol::Dnsaddr(_)
)
}) {
if dns_lookups == MAX_DNS_LOOKUPS {
log::debug!("Too many DNS lookups. Dropping unresolved {}.", addr);
Expand Down
6 changes: 6 additions & 0 deletions transports/noise/src/protocol/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ impl Keypair<X25519> {
}
}

impl Default for Keypair<X25519> {
fn default() -> Self {
Self::new()
}
}

/// Promote a X25519 secret key into a keypair.
impl From<SecretKey<X25519>> for Keypair<X25519> {
fn from(secret: SecretKey<X25519>) -> Keypair<X25519> {
Expand Down
6 changes: 6 additions & 0 deletions transports/noise/src/protocol/x25519_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl Keypair<X25519Spec> {
}
}

impl Default for Keypair<X25519Spec> {
fn default() -> Self {
Self::new()
}
}

/// Promote a X25519 secret key into a keypair.
impl From<SecretKey<X25519Spec>> for Keypair<X25519Spec> {
fn from(secret: SecretKey<X25519Spec>) -> Keypair<X25519Spec> {
Expand Down
6 changes: 6 additions & 0 deletions transports/tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ where
}
}

impl<T: Provider + Send> Default for GenTcpConfig<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> Transport for GenTcpConfig<T>
where
T: Provider + Send + 'static,
Expand Down
6 changes: 6 additions & 0 deletions transports/uds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ impl $uds_config {
}
}

impl Default for $uds_config {
fn default() -> Self {
Self::new()
}
}

impl Transport for $uds_config {
type Output = $unix_stream;
type Error = io::Error;
Expand Down
10 changes: 5 additions & 5 deletions transports/wasm-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ impl Stream for Listen {
};

if let Some(addrs) = event.new_addrs() {
for addr in addrs.into_iter() {
let addr = js_value_to_addr(&addr)?;
for addr in addrs.iter() {
let addr = js_value_to_addr(addr)?;
self.pending_events
.push_back(ListenerEvent::NewAddress(addr));
}
}

if let Some(upgrades) = event.new_connections() {
for upgrade in upgrades.into_iter().cloned() {
for upgrade in upgrades.iter().cloned() {
let upgrade: ffi::ConnectionEvent = upgrade.into();
self.pending_events.push_back(ListenerEvent::Upgrade {
local_addr: upgrade.local_addr().parse()?,
Expand All @@ -337,8 +337,8 @@ impl Stream for Listen {
}

if let Some(addrs) = event.expired_addrs() {
for addr in addrs.into_iter() {
match js_value_to_addr(&addr) {
for addr in addrs.iter() {
match js_value_to_addr(addr) {
Ok(addr) => self
.pending_events
.push_back(ListenerEvent::NewAddress(addr)),
Expand Down

0 comments on commit 22fbce3

Please sign in to comment.