From 22865377d954f15c4abf3002fac7ebee5c0bfe27 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Fri, 10 Sep 2021 15:22:38 +0300 Subject: [PATCH] Fix clippy warnings --- core/src/connection/manager/task.rs | 2 +- core/src/connection/pool.rs | 2 +- core/src/identity/rsa.rs | 9 ++-- core/src/peer_id.rs | 2 +- core/src/signed_envelope.rs | 2 +- .../src/length_delimited.rs | 2 +- protocols/gossipsub/src/behaviour.rs | 40 ++++++++-------- protocols/gossipsub/src/protocol.rs | 6 +-- protocols/kad/src/handler.rs | 48 +++++++------------ protocols/kad/src/kbucket/entry.rs | 2 +- protocols/kad/src/query/peers/fixed.rs | 6 ++- protocols/mdns/src/behaviour.rs | 2 +- protocols/mdns/src/dns.rs | 4 +- protocols/relay/src/behaviour.rs | 4 +- .../relay/src/protocol/incoming_dst_req.rs | 2 +- swarm-derive/src/lib.rs | 42 ++++++++-------- swarm/src/behaviour.rs | 2 +- swarm/src/lib.rs | 6 +-- swarm/src/protocols_handler.rs | 5 +- swarm/src/registry.rs | 2 +- transports/dns/src/lib.rs | 2 +- transports/noise/src/io.rs | 4 +- transports/noise/src/protocol/x25519.rs | 2 +- transports/noise/src/protocol/x25519_spec.rs | 2 +- transports/websocket/src/framed.rs | 18 ++----- 25 files changed, 96 insertions(+), 122 deletions(-) diff --git a/core/src/connection/manager/task.rs b/core/src/connection/manager/task.rs index 0ed331c66253..5860bcc6c9d7 100644 --- a/core/src/connection/manager/task.rs +++ b/core/src/connection/manager/task.rs @@ -348,7 +348,7 @@ where Poll::Ready(Ok(())) => { let event = Event::Closed { id: this.id, - error: error.map(|limit| ConnectionError::ConnectionLimit(limit)), + error: error.map(ConnectionError::ConnectionLimit), handler, }; this.state = State::Terminating(event); diff --git a/core/src/connection/pool.rs b/core/src/connection/pool.rs index 11861600c211..f147f766d4da 100644 --- a/core/src/connection/pool.rs +++ b/core/src/connection/pool.rs @@ -434,7 +434,7 @@ impl Pool { /// Returns an iterator for information on all pending outgoing connections. pub fn iter_pending_outgoing(&self) -> impl Iterator> { self.iter_pending_info() - .filter_map(|(_, ref endpoint, ref peer_id)| match endpoint { + .filter_map(|(_, ref endpoint, peer_id)| match endpoint { ConnectedPoint::Listener { .. } => None, ConnectedPoint::Dialer { address } => Some(OutgoingInfo { address, diff --git a/core/src/identity/rsa.rs b/core/src/identity/rsa.rs index 752bb1567647..29d9f7817ae5 100644 --- a/core/src/identity/rsa.rs +++ b/core/src/identity/rsa.rs @@ -39,7 +39,7 @@ impl Keypair { /// /// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5 pub fn from_pkcs8(der: &mut [u8]) -> Result { - let kp = RsaKeyPair::from_pkcs8(&der) + let kp = RsaKeyPair::from_pkcs8(der) .map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo").source(e))?; der.zeroize(); Ok(Keypair(Arc::new(kp))) @@ -54,7 +54,7 @@ impl Keypair { pub fn sign(&self, data: &[u8]) -> Result, SigningError> { let mut signature = vec![0; self.0.public_modulus_len()]; let rng = SystemRandom::new(); - match self.0.sign(&RSA_PKCS1_SHA256, &rng, &data, &mut signature) { + match self.0.sign(&RSA_PKCS1_SHA256, &rng, data, &mut signature) { Ok(()) => Ok(signature), Err(e) => Err(SigningError::new("RSA").source(e)), } @@ -94,11 +94,10 @@ impl PublicKey { subjectPublicKey: Asn1SubjectPublicKey(self.clone()), }; let mut buf = Vec::new(); - let buf = spki + spki .encode(&mut buf) .map(|_| buf) - .expect("RSA X.509 public key encoding failed."); - buf + .expect("RSA X.509 public key encoding failed.") } /// Decode an RSA public key from a DER-encoded X.509 SubjectPublicKeyInfo diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index 5a9ae8b0341d..6e3823e64ed8 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -66,7 +66,7 @@ impl PeerId { /// Parses a `PeerId` from bytes. pub fn from_bytes(data: &[u8]) -> Result { - PeerId::from_multihash(Multihash::from_bytes(&data)?) + PeerId::from_multihash(Multihash::from_bytes(data)?) .map_err(|mh| Error::UnsupportedCode(mh.code())) } diff --git a/core/src/signed_envelope.rs b/core/src/signed_envelope.rs index afa00a237464..a528cb0811ff 100644 --- a/core/src/signed_envelope.rs +++ b/core/src/signed_envelope.rs @@ -53,7 +53,7 @@ impl SignedEnvelope { domain_separation: String, expected_payload_type: &[u8], ) -> Result<&[u8], ReadPayloadError> { - if &self.payload_type != expected_payload_type { + if self.payload_type != expected_payload_type { return Err(ReadPayloadError::UnexpectedPayloadType { expected: expected_payload_type.to_vec(), got: self.payload_type.clone(), diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index abb622eed307..981dfff82f8e 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -125,7 +125,7 @@ impl LengthDelimited { let mut this = self.project(); while !this.write_buffer.is_empty() { - match this.inner.as_mut().poll_write(cx, &this.write_buffer) { + match this.inner.as_mut().poll_write(cx, this.write_buffer) { Poll::Pending => return Poll::Pending, Poll::Ready(Ok(0)) => { return Poll::Ready(Err(io::Error::new( diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index e3adfdcfc1a2..8da39b7e8de8 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -157,8 +157,8 @@ enum PublishConfig { impl PublishConfig { pub fn get_own_id(&self) -> Option<&PeerId> { match self { - Self::Signing { author, .. } => Some(&author), - Self::Author(author) => Some(&author), + Self::Signing { author, .. } => Some(author), + Self::Author(author) => Some(author), _ => None, } } @@ -381,7 +381,7 @@ where // We do not allow configurations where a published message would also be rejected if it // were received locally. - validate_config(&privacy, &config.validation_mode())?; + validate_config(&privacy, config.validation_mode())?; // Set up message publishing parameters. @@ -990,7 +990,7 @@ where get_random_peers( &self.topic_peers, &self.connected_peers, - &topic_hash, + topic_hash, self.config.prune_peers(), |p| p != peer && !self.score_below_threshold(p, |_| 0.0).0, ) @@ -1337,7 +1337,7 @@ where *peer_id, vec![&topic_hash], &self.mesh, - self.peer_topics.get(&peer_id), + self.peer_topics.get(peer_id), &mut self.events, &self.connected_peers, ); @@ -1396,7 +1396,7 @@ where always_update_backoff: bool, ) { let mut update_backoff = always_update_backoff; - if let Some(peers) = self.mesh.get_mut(&topic_hash) { + if let Some(peers) = self.mesh.get_mut(topic_hash) { // remove the peer if it exists in the mesh if peers.remove(peer_id) { debug!( @@ -1416,7 +1416,7 @@ where *peer_id, topic_hash, &self.mesh, - self.peer_topics.get(&peer_id), + self.peer_topics.get(peer_id), &mut self.events, &self.connected_peers, ); @@ -1429,7 +1429,7 @@ where self.config.prune_backoff() }; // is there a backoff specified by the peer? if so obey it. - self.backoffs.update_backoff(&topic_hash, peer_id, time); + self.backoffs.update_backoff(topic_hash, peer_id, time); } } @@ -1570,7 +1570,7 @@ where own_id != propagation_source && raw_message.source.as_ref().map_or(false, |s| s == own_id) } else { - self.published_message_ids.contains(&msg_id) + self.published_message_ids.contains(msg_id) }; if self_published { @@ -2176,7 +2176,7 @@ where "HEARTBEAT: Fanout topic removed due to timeout. Topic: {:?}", topic_hash ); - fanout.remove(&topic_hash); + fanout.remove(topic_hash); return false; } true @@ -2195,7 +2195,7 @@ where // is the peer still subscribed to the topic? match self.peer_topics.get(peer) { Some(topics) => { - if !topics.contains(&topic_hash) || score(peer) < publish_threshold { + if !topics.contains(topic_hash) || score(peer) < publish_threshold { debug!( "HEARTBEAT: Peer removed from fanout for topic: {:?}", topic_hash @@ -2291,7 +2291,7 @@ where fn emit_gossip(&mut self) { let mut rng = thread_rng(); for (topic_hash, peers) in self.mesh.iter().chain(self.fanout.iter()) { - let mut message_ids = self.mcache.get_gossip_message_ids(&topic_hash); + let mut message_ids = self.mcache.get_gossip_message_ids(topic_hash); if message_ids.is_empty() { return; } @@ -2319,7 +2319,7 @@ where let to_msg_peers = get_random_peers_dynamic( &self.topic_peers, &self.connected_peers, - &topic_hash, + topic_hash, n_map, |peer| { !peers.contains(peer) @@ -2438,7 +2438,7 @@ where *peer, topic_hash, &self.mesh, - self.peer_topics.get(&peer), + self.peer_topics.get(peer), &mut self.events, &self.connected_peers, ); @@ -2483,7 +2483,7 @@ where // add mesh peers let topic = &message.topic; // mesh - if let Some(mesh_peers) = self.mesh.get(&topic) { + if let Some(mesh_peers) = self.mesh.get(topic) { for peer_id in mesh_peers { if Some(peer_id) != propagation_source && Some(peer_id) != message.source.as_ref() { recipient_peers.insert(*peer_id); @@ -2877,13 +2877,13 @@ where // remove peer from all mappings for topic in topics { // check the mesh for the topic - if let Some(mesh_peers) = self.mesh.get_mut(&topic) { + if let Some(mesh_peers) = self.mesh.get_mut(topic) { // check if the peer is in the mesh and remove it mesh_peers.remove(peer_id); } // remove from topic_peers - if let Some(peer_list) = self.topic_peers.get_mut(&topic) { + if let Some(peer_list) = self.topic_peers.get_mut(topic) { if !peer_list.remove(peer_id) { // debugging purposes warn!( @@ -2900,7 +2900,7 @@ where // remove from fanout self.fanout - .get_mut(&topic) + .get_mut(topic) .map(|peers| peers.remove(peer_id)); } } @@ -2943,7 +2943,7 @@ where // Add the IP to the peer scoring system if let Some((peer_score, ..)) = &mut self.peer_score { if let Some(ip) = get_ip_addr(endpoint.get_remote_address()) { - peer_score.add_ip(&peer_id, ip); + peer_score.add_ip(peer_id, ip); } else { trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", @@ -3041,7 +3041,7 @@ where ) } if let Some(ip) = get_ip_addr(endpoint_new.get_remote_address()) { - peer_score.add_ip(&peer, ip); + peer_score.add_ip(peer, ip); } else { trace!( "Couldn't extract ip from endpoint of peer {} with endpoint {:?}", diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index d62605f6807b..c0a3ec6a9bd8 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -194,7 +194,7 @@ impl GossipsubCodec { } }; - let source = match PeerId::from_bytes(&from) { + let source = match PeerId::from_bytes(from) { Ok(v) => v, Err(_) => { debug!("Signature verification failed: Invalid Peer Id"); @@ -214,8 +214,8 @@ impl GossipsubCodec { // obtained from the inlined source peer_id. let public_key = match message .key - .as_ref() - .map(|key| PublicKey::from_protobuf_encoding(&key)) + .as_deref() + .map(PublicKey::from_protobuf_encoding) { Some(Ok(key)) => key, _ => match PublicKey::from_protobuf_encoding(&source.to_bytes()[2..]) { diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 3c955bb428a5..b92c89bfee55 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -803,16 +803,12 @@ fn advance_substream( true, ), Err(error) => { - let event = if let Some(user_data) = user_data { - Some(ProtocolsHandlerEvent::Custom( - KademliaHandlerEvent::QueryError { - error: KademliaHandlerQueryErr::Io(error), - user_data, - }, - )) - } else { - None - }; + let event = user_data.map(|user_data| { + ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError { + error: KademliaHandlerQueryErr::Io(error), + user_data, + }) + }); (None, event, false) } @@ -823,16 +819,12 @@ fn advance_substream( false, ), Poll::Ready(Err(error)) => { - let event = if let Some(user_data) = user_data { - Some(ProtocolsHandlerEvent::Custom( - KademliaHandlerEvent::QueryError { - error: KademliaHandlerQueryErr::Io(error), - user_data, - }, - )) - } else { - None - }; + let event = user_data.map(|user_data| { + ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError { + error: KademliaHandlerQueryErr::Io(error), + user_data, + }) + }); (None, event, false) } @@ -857,16 +849,12 @@ fn advance_substream( false, ), Poll::Ready(Err(error)) => { - let event = if let Some(user_data) = user_data { - Some(ProtocolsHandlerEvent::Custom( - KademliaHandlerEvent::QueryError { - error: KademliaHandlerQueryErr::Io(error), - user_data, - }, - )) - } else { - None - }; + let event = user_data.map(|user_data| { + ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError { + error: KademliaHandlerQueryErr::Io(error), + user_data, + }) + }); (None, event, false) } diff --git a/protocols/kad/src/kbucket/entry.rs b/protocols/kad/src/kbucket/entry.rs index 3447146007be..7ccf2017e999 100644 --- a/protocols/kad/src/kbucket/entry.rs +++ b/protocols/kad/src/kbucket/entry.rs @@ -201,7 +201,7 @@ where let (node, status, _pos) = self .0 .bucket - .remove(&self.0.key) + .remove(self.0.key) .expect("We can only build a PresentEntry if the entry is in the bucket; QED"); EntryView { node, status } } diff --git a/protocols/kad/src/query/peers/fixed.rs b/protocols/kad/src/query/peers/fixed.rs index e4be4094eb12..6647fb66aa37 100644 --- a/protocols/kad/src/query/peers/fixed.rs +++ b/protocols/kad/src/query/peers/fixed.rs @@ -58,16 +58,18 @@ enum PeerState { } impl FixedPeersIter { + #[allow(clippy::needless_collect)] pub fn new(peers: I, parallelism: NonZeroUsize) -> Self where I: IntoIterator, { - let peers = peers.into_iter().collect::>(); + let peers_vec = peers.into_iter().collect::>(); Self { parallelism, peers: FnvHashMap::default(), - iter: peers.into_iter(), + + iter: peers_vec.into_iter(), state: State::Waiting { num_waiting: 0 }, } } diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index a3c90aeb1f6a..156c805a4d70 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -226,7 +226,7 @@ impl Mdns { let mut addrs: Vec = Vec::new(); for addr in peer.addresses() { - if let Some(new_addr) = address_translation(&addr, &observed) { + if let Some(new_addr) = address_translation(addr, &observed) { addrs.push(new_addr.clone()) } addrs.push(addr.clone()) diff --git a/protocols/mdns/src/dns.rs b/protocols/mdns/src/dns.rs index 92fd980c89d2..9bd1181dd742 100644 --- a/protocols/mdns/src/dns.rs +++ b/protocols/mdns/src/dns.rs @@ -228,11 +228,11 @@ fn query_response_packet(id: u16, peer_id: &[u8], records: &[Vec], ttl: u32) // Peer Id. append_u16(&mut out, peer_id.len() as u16); - out.extend_from_slice(&peer_id); + out.extend_from_slice(peer_id); // The TXT records. for record in records { - out.extend_from_slice(&record); + out.extend_from_slice(record); } out diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 35f97647efc8..8fe510883aaa 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -296,7 +296,7 @@ impl NetworkBehaviour for Relay { .push_back(NetworkBehaviourAction::NotifyHandler { peer_id: *peer_id, handler: NotifyHandler::Any, - event: event, + event, }); } } @@ -640,7 +640,7 @@ impl NetworkBehaviour for Relay { dst_peer_id, send_back, })) => { - if let Some(_) = self.connected_peers.get(&relay_peer_id) { + if self.connected_peers.get(&relay_peer_id).is_some() { // In case we are already listening via the relay, // prefer the primary connection. let handler = self diff --git a/protocols/relay/src/protocol/incoming_dst_req.rs b/protocols/relay/src/protocol/incoming_dst_req.rs index d68a15121f5d..ffaeb59aaa79 100644 --- a/protocols/relay/src/protocol/incoming_dst_req.rs +++ b/protocols/relay/src/protocol/incoming_dst_req.rs @@ -51,7 +51,7 @@ impl IncomingDstReq { /// Creates a `IncomingDstReq`. pub(crate) fn new(stream: Framed, src: Peer) -> Self { IncomingDstReq { - stream: stream, + stream, src, } } diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index eef08d15c07e..e606dda0c7c0 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -151,7 +151,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -169,7 +169,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -186,7 +186,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -199,7 +199,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_connection_established()`. let inject_connection_established_stmts = { data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -212,7 +212,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // Build the list of statements to put in the body of `inject_address_change()`. let inject_address_change_stmts = { data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -230,7 +230,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .enumerate() // The outmost handler belongs to the last behaviour. .rev() - .filter(|f| !is_ignored(&f.1)) + .filter(|f| !is_ignored(f.1)) .enumerate() .map(move |(enum_n, (field_n, field))| { let handler = if field_n == 0 { @@ -257,7 +257,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let inject_addr_reach_failure_stmts = { data_struct.fields.iter().enumerate().filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -276,7 +276,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .enumerate() // The outmost handler belongs to the last behaviour. .rev() - .filter(|f| !is_ignored(&f.1)) + .filter(|f| !is_ignored(f.1)) .enumerate() .map(move |(enum_n, (field_n, field))| { let handler = if field_n == 0 { @@ -311,7 +311,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .rev() - .filter(|f| !is_ignored(&f.1)) + .filter(|f| !is_ignored(f.1)) .enumerate() .map(move |(enum_n, (field_n, field))| { let handler = if field_n == 0 { @@ -341,7 +341,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -359,7 +359,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -377,7 +377,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -395,7 +395,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -413,7 +413,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } @@ -431,7 +431,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -448,7 +448,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { .iter() .enumerate() .filter_map(move |(field_n, field)| { - if is_ignored(&field) { + if is_ignored(field) { return None; } Some(match field.ident { @@ -462,7 +462,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // // The event type is a construction of nested `#either_ident`s of the events of the children. // We call `inject_event` on the corresponding child. - let inject_node_event_stmts = data_struct.fields.iter().enumerate().filter(|f| !is_ignored(&f.1)).enumerate().map(|(enum_n, (field_n, field))| { + let inject_node_event_stmts = data_struct.fields.iter().enumerate().filter(|f| !is_ignored(f.1)).enumerate().map(|(enum_n, (field_n, field))| { let mut elem = if enum_n != 0 { quote!{ #either_ident::Second(ev) } } else { @@ -483,7 +483,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let protocols_handler_ty = { let mut ph_ty = None; for field in data_struct.fields.iter() { - if is_ignored(&field) { + if is_ignored(field) { continue; } let ty = &field.ty; @@ -503,7 +503,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let mut out_handler = None; for (field_n, field) in data_struct.fields.iter().enumerate() { - if is_ignored(&field) { + if is_ignored(field) { continue; } @@ -553,7 +553,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { // List of statements to put in `poll()`. // // We poll each child one by one and wrap around the output. - let poll_stmts = data_struct.fields.iter().enumerate().filter(|f| !is_ignored(&f.1)).enumerate().map(|(enum_n, (field_n, field))| { + let poll_stmts = data_struct.fields.iter().enumerate().filter(|f| !is_ignored(f.1)).enumerate().map(|(enum_n, (field_n, field))| { let field_name = match field.ident { Some(ref i) => quote!{ self.#i }, None => quote!{ self.#field_n }, @@ -576,7 +576,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { let mut out_handler = None; for (f_n, f) in data_struct.fields.iter().enumerate() { - if is_ignored(&f) { + if is_ignored(f) { continue; } diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 085439aa1b1f..c75049e6a9b9 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -675,7 +675,7 @@ where } => NetworkBehaviourAction::NotifyHandler { peer_id, handler, - event: event, + event, }, NetworkBehaviourAction::ReportObservedAddr { address, score } => { NetworkBehaviourAction::ReportObservedAddr { address, score } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index dcccd46af792..a903113c2a9e 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -333,7 +333,7 @@ where pub fn dial_addr(&mut self, addr: Multiaddr) -> Result<(), DialError> { let handler = self.behaviour.new_handler(); self.dial_addr_with_handler(addr, handler) - .map_err(|e| DialError::from_network_dial_error(e)) + .map_err(DialError::from_network_dial_error) .map_err(|(e, _)| e) } @@ -392,7 +392,7 @@ where Err(error) => { let (error, handler) = DialError::from_network_dial_error(error); self.behaviour.inject_dial_failure( - &peer_id, + peer_id, handler.into_protocols_handler(), error.clone(), ); @@ -1051,7 +1051,7 @@ impl<'a> PollParameters for SwarmPollParameters<'a> { } fn local_peer_id(&self) -> &PeerId { - &self.local_peer_id + self.local_peer_id } } diff --git a/swarm/src/protocols_handler.rs b/swarm/src/protocols_handler.rs index 208d3ce6e130..2000dbc3fb0a 100644 --- a/swarm/src/protocols_handler.rs +++ b/swarm/src/protocols_handler.rs @@ -523,10 +523,7 @@ pub enum KeepAlive { impl KeepAlive { /// Returns true for `Yes`, false otherwise. pub fn is_yes(&self) -> bool { - match *self { - KeepAlive::Yes => true, - _ => false, - } + matches!(*self, KeepAlive::Yes) } } diff --git a/swarm/src/registry.rs b/swarm/src/registry.rs index 5819ecf1e4e6..76892edf981d 100644 --- a/swarm/src/registry.rs +++ b/swarm/src/registry.rs @@ -285,7 +285,7 @@ impl<'a> Iterator for AddressIter<'a> { } let item = &self.items[self.offset]; self.offset += 1; - Some(&item) + Some(item) } fn size_hint(&self) -> (usize, Option) { diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 6174c1e362cc..2cfc27f93a67 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -76,7 +76,7 @@ pub use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; pub use trust_dns_resolver::error::{ResolveError, ResolveErrorKind}; /// The prefix for `dnsaddr` protocol TXT record lookups. -const DNSADDR_PREFIX: &'static str = "_dnsaddr."; +const DNSADDR_PREFIX: &str = "_dnsaddr."; /// The maximum number of dialing attempts to resolved addresses. const MAX_DIAL_ATTEMPTS: usize = 16; diff --git a/transports/noise/src/io.rs b/transports/noise/src/io.rs index 37e35ecbeee1..afeee65363ae 100644 --- a/transports/noise/src/io.rs +++ b/transports/noise/src/io.rs @@ -114,7 +114,7 @@ impl AsyncWrite for NoiseOutput { if this.send_offset == MAX_FRAME_LEN { trace!("write: sending {} bytes", MAX_FRAME_LEN); ready!(io.as_mut().poll_ready(cx))?; - io.as_mut().start_send(&frame_buf)?; + io.as_mut().start_send(frame_buf)?; this.send_offset = 0; } @@ -138,7 +138,7 @@ impl AsyncWrite for NoiseOutput { if this.send_offset > 0 { ready!(io.as_mut().poll_ready(cx))?; trace!("flush: sending {} bytes", this.send_offset); - io.as_mut().start_send(&frame_buf)?; + io.as_mut().start_send(frame_buf)?; this.send_offset = 0; } diff --git a/transports/noise/src/protocol/x25519.rs b/transports/noise/src/protocol/x25519.rs index c0d3936ee36b..fb2169098060 100644 --- a/transports/noise/src/protocol/x25519.rs +++ b/transports/noise/src/protocol/x25519.rs @@ -246,7 +246,7 @@ impl snow::types::Dh for Keypair { fn set(&mut self, sk: &[u8]) { let mut secret = [0u8; 32]; - secret.copy_from_slice(&sk); + secret.copy_from_slice(sk); self.secret = SecretKey(X25519(secret)); // Copy self.public = PublicKey(X25519(x25519(secret, X25519_BASEPOINT_BYTES))); secret.zeroize(); diff --git a/transports/noise/src/protocol/x25519_spec.rs b/transports/noise/src/protocol/x25519_spec.rs index 2f2c24237a61..839a5b77253a 100644 --- a/transports/noise/src/protocol/x25519_spec.rs +++ b/transports/noise/src/protocol/x25519_spec.rs @@ -162,7 +162,7 @@ impl snow::types::Dh for Keypair { fn set(&mut self, sk: &[u8]) { let mut secret = [0u8; 32]; - secret.copy_from_slice(&sk); + secret.copy_from_slice(sk); self.secret = SecretKey(X25519Spec(secret)); // Copy self.public = PublicKey(X25519Spec(x25519(secret, X25519_BASEPOINT_BYTES))); secret.zeroize(); diff --git a/transports/websocket/src/framed.rs b/transports/websocket/src/framed.rs index dc57cb8e220f..52635ec5ba02 100644 --- a/transports/websocket/src/framed.rs +++ b/transports/websocket/src/framed.rs @@ -494,27 +494,15 @@ impl IncomingData { } pub fn is_binary(&self) -> bool { - if let IncomingData::Binary(_) = self { - true - } else { - false - } + matches!(self, IncomingData::Binary(_)) } pub fn is_text(&self) -> bool { - if let IncomingData::Text(_) = self { - true - } else { - false - } + matches!(self, IncomingData::Text(_)) } pub fn is_pong(&self) -> bool { - if let IncomingData::Pong(_) = self { - true - } else { - false - } + matches!(self, IncomingData::Pong(_)) } pub fn into_bytes(self) -> Vec {