Skip to content

Commit 2286537

Browse files
committed
Fix clippy warnings
1 parent 70a067a commit 2286537

File tree

25 files changed

+96
-122
lines changed

25 files changed

+96
-122
lines changed

core/src/connection/manager/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ where
348348
Poll::Ready(Ok(())) => {
349349
let event = Event::Closed {
350350
id: this.id,
351-
error: error.map(|limit| ConnectionError::ConnectionLimit(limit)),
351+
error: error.map(ConnectionError::ConnectionLimit),
352352
handler,
353353
};
354354
this.state = State::Terminating(event);

core/src/connection/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<THandler: IntoConnectionHandler, TTransErr> Pool<THandler, TTransErr> {
434434
/// Returns an iterator for information on all pending outgoing connections.
435435
pub fn iter_pending_outgoing(&self) -> impl Iterator<Item = OutgoingInfo<'_>> {
436436
self.iter_pending_info()
437-
.filter_map(|(_, ref endpoint, ref peer_id)| match endpoint {
437+
.filter_map(|(_, ref endpoint, peer_id)| match endpoint {
438438
ConnectedPoint::Listener { .. } => None,
439439
ConnectedPoint::Dialer { address } => Some(OutgoingInfo {
440440
address,

core/src/identity/rsa.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Keypair {
3939
///
4040
/// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5
4141
pub fn from_pkcs8(der: &mut [u8]) -> Result<Keypair, DecodingError> {
42-
let kp = RsaKeyPair::from_pkcs8(&der)
42+
let kp = RsaKeyPair::from_pkcs8(der)
4343
.map_err(|e| DecodingError::new("RSA PKCS#8 PrivateKeyInfo").source(e))?;
4444
der.zeroize();
4545
Ok(Keypair(Arc::new(kp)))
@@ -54,7 +54,7 @@ impl Keypair {
5454
pub fn sign(&self, data: &[u8]) -> Result<Vec<u8>, SigningError> {
5555
let mut signature = vec![0; self.0.public_modulus_len()];
5656
let rng = SystemRandom::new();
57-
match self.0.sign(&RSA_PKCS1_SHA256, &rng, &data, &mut signature) {
57+
match self.0.sign(&RSA_PKCS1_SHA256, &rng, data, &mut signature) {
5858
Ok(()) => Ok(signature),
5959
Err(e) => Err(SigningError::new("RSA").source(e)),
6060
}
@@ -94,11 +94,10 @@ impl PublicKey {
9494
subjectPublicKey: Asn1SubjectPublicKey(self.clone()),
9595
};
9696
let mut buf = Vec::new();
97-
let buf = spki
97+
spki
9898
.encode(&mut buf)
9999
.map(|_| buf)
100-
.expect("RSA X.509 public key encoding failed.");
101-
buf
100+
.expect("RSA X.509 public key encoding failed.")
102101
}
103102

104103
/// Decode an RSA public key from a DER-encoded X.509 SubjectPublicKeyInfo

core/src/peer_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl PeerId {
6666

6767
/// Parses a `PeerId` from bytes.
6868
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error> {
69-
PeerId::from_multihash(Multihash::from_bytes(&data)?)
69+
PeerId::from_multihash(Multihash::from_bytes(data)?)
7070
.map_err(|mh| Error::UnsupportedCode(mh.code()))
7171
}
7272

core/src/signed_envelope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl SignedEnvelope {
5353
domain_separation: String,
5454
expected_payload_type: &[u8],
5555
) -> Result<&[u8], ReadPayloadError> {
56-
if &self.payload_type != expected_payload_type {
56+
if self.payload_type != expected_payload_type {
5757
return Err(ReadPayloadError::UnexpectedPayloadType {
5858
expected: expected_payload_type.to_vec(),
5959
got: self.payload_type.clone(),

misc/multistream-select/src/length_delimited.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<R> LengthDelimited<R> {
125125
let mut this = self.project();
126126

127127
while !this.write_buffer.is_empty() {
128-
match this.inner.as_mut().poll_write(cx, &this.write_buffer) {
128+
match this.inner.as_mut().poll_write(cx, this.write_buffer) {
129129
Poll::Pending => return Poll::Pending,
130130
Poll::Ready(Ok(0)) => {
131131
return Poll::Ready(Err(io::Error::new(

protocols/gossipsub/src/behaviour.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ enum PublishConfig {
157157
impl PublishConfig {
158158
pub fn get_own_id(&self) -> Option<&PeerId> {
159159
match self {
160-
Self::Signing { author, .. } => Some(&author),
161-
Self::Author(author) => Some(&author),
160+
Self::Signing { author, .. } => Some(author),
161+
Self::Author(author) => Some(author),
162162
_ => None,
163163
}
164164
}
@@ -381,7 +381,7 @@ where
381381

382382
// We do not allow configurations where a published message would also be rejected if it
383383
// were received locally.
384-
validate_config(&privacy, &config.validation_mode())?;
384+
validate_config(&privacy, config.validation_mode())?;
385385

386386
// Set up message publishing parameters.
387387

@@ -990,7 +990,7 @@ where
990990
get_random_peers(
991991
&self.topic_peers,
992992
&self.connected_peers,
993-
&topic_hash,
993+
topic_hash,
994994
self.config.prune_peers(),
995995
|p| p != peer && !self.score_below_threshold(p, |_| 0.0).0,
996996
)
@@ -1337,7 +1337,7 @@ where
13371337
*peer_id,
13381338
vec![&topic_hash],
13391339
&self.mesh,
1340-
self.peer_topics.get(&peer_id),
1340+
self.peer_topics.get(peer_id),
13411341
&mut self.events,
13421342
&self.connected_peers,
13431343
);
@@ -1396,7 +1396,7 @@ where
13961396
always_update_backoff: bool,
13971397
) {
13981398
let mut update_backoff = always_update_backoff;
1399-
if let Some(peers) = self.mesh.get_mut(&topic_hash) {
1399+
if let Some(peers) = self.mesh.get_mut(topic_hash) {
14001400
// remove the peer if it exists in the mesh
14011401
if peers.remove(peer_id) {
14021402
debug!(
@@ -1416,7 +1416,7 @@ where
14161416
*peer_id,
14171417
topic_hash,
14181418
&self.mesh,
1419-
self.peer_topics.get(&peer_id),
1419+
self.peer_topics.get(peer_id),
14201420
&mut self.events,
14211421
&self.connected_peers,
14221422
);
@@ -1429,7 +1429,7 @@ where
14291429
self.config.prune_backoff()
14301430
};
14311431
// is there a backoff specified by the peer? if so obey it.
1432-
self.backoffs.update_backoff(&topic_hash, peer_id, time);
1432+
self.backoffs.update_backoff(topic_hash, peer_id, time);
14331433
}
14341434
}
14351435

@@ -1570,7 +1570,7 @@ where
15701570
own_id != propagation_source
15711571
&& raw_message.source.as_ref().map_or(false, |s| s == own_id)
15721572
} else {
1573-
self.published_message_ids.contains(&msg_id)
1573+
self.published_message_ids.contains(msg_id)
15741574
};
15751575

15761576
if self_published {
@@ -2176,7 +2176,7 @@ where
21762176
"HEARTBEAT: Fanout topic removed due to timeout. Topic: {:?}",
21772177
topic_hash
21782178
);
2179-
fanout.remove(&topic_hash);
2179+
fanout.remove(topic_hash);
21802180
return false;
21812181
}
21822182
true
@@ -2195,7 +2195,7 @@ where
21952195
// is the peer still subscribed to the topic?
21962196
match self.peer_topics.get(peer) {
21972197
Some(topics) => {
2198-
if !topics.contains(&topic_hash) || score(peer) < publish_threshold {
2198+
if !topics.contains(topic_hash) || score(peer) < publish_threshold {
21992199
debug!(
22002200
"HEARTBEAT: Peer removed from fanout for topic: {:?}",
22012201
topic_hash
@@ -2291,7 +2291,7 @@ where
22912291
fn emit_gossip(&mut self) {
22922292
let mut rng = thread_rng();
22932293
for (topic_hash, peers) in self.mesh.iter().chain(self.fanout.iter()) {
2294-
let mut message_ids = self.mcache.get_gossip_message_ids(&topic_hash);
2294+
let mut message_ids = self.mcache.get_gossip_message_ids(topic_hash);
22952295
if message_ids.is_empty() {
22962296
return;
22972297
}
@@ -2319,7 +2319,7 @@ where
23192319
let to_msg_peers = get_random_peers_dynamic(
23202320
&self.topic_peers,
23212321
&self.connected_peers,
2322-
&topic_hash,
2322+
topic_hash,
23232323
n_map,
23242324
|peer| {
23252325
!peers.contains(peer)
@@ -2438,7 +2438,7 @@ where
24382438
*peer,
24392439
topic_hash,
24402440
&self.mesh,
2441-
self.peer_topics.get(&peer),
2441+
self.peer_topics.get(peer),
24422442
&mut self.events,
24432443
&self.connected_peers,
24442444
);
@@ -2483,7 +2483,7 @@ where
24832483
// add mesh peers
24842484
let topic = &message.topic;
24852485
// mesh
2486-
if let Some(mesh_peers) = self.mesh.get(&topic) {
2486+
if let Some(mesh_peers) = self.mesh.get(topic) {
24872487
for peer_id in mesh_peers {
24882488
if Some(peer_id) != propagation_source && Some(peer_id) != message.source.as_ref() {
24892489
recipient_peers.insert(*peer_id);
@@ -2877,13 +2877,13 @@ where
28772877
// remove peer from all mappings
28782878
for topic in topics {
28792879
// check the mesh for the topic
2880-
if let Some(mesh_peers) = self.mesh.get_mut(&topic) {
2880+
if let Some(mesh_peers) = self.mesh.get_mut(topic) {
28812881
// check if the peer is in the mesh and remove it
28822882
mesh_peers.remove(peer_id);
28832883
}
28842884

28852885
// remove from topic_peers
2886-
if let Some(peer_list) = self.topic_peers.get_mut(&topic) {
2886+
if let Some(peer_list) = self.topic_peers.get_mut(topic) {
28872887
if !peer_list.remove(peer_id) {
28882888
// debugging purposes
28892889
warn!(
@@ -2900,7 +2900,7 @@ where
29002900

29012901
// remove from fanout
29022902
self.fanout
2903-
.get_mut(&topic)
2903+
.get_mut(topic)
29042904
.map(|peers| peers.remove(peer_id));
29052905
}
29062906
}
@@ -2943,7 +2943,7 @@ where
29432943
// Add the IP to the peer scoring system
29442944
if let Some((peer_score, ..)) = &mut self.peer_score {
29452945
if let Some(ip) = get_ip_addr(endpoint.get_remote_address()) {
2946-
peer_score.add_ip(&peer_id, ip);
2946+
peer_score.add_ip(peer_id, ip);
29472947
} else {
29482948
trace!(
29492949
"Couldn't extract ip from endpoint of peer {} with endpoint {:?}",
@@ -3041,7 +3041,7 @@ where
30413041
)
30423042
}
30433043
if let Some(ip) = get_ip_addr(endpoint_new.get_remote_address()) {
3044-
peer_score.add_ip(&peer, ip);
3044+
peer_score.add_ip(peer, ip);
30453045
} else {
30463046
trace!(
30473047
"Couldn't extract ip from endpoint of peer {} with endpoint {:?}",

protocols/gossipsub/src/protocol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl GossipsubCodec {
194194
}
195195
};
196196

197-
let source = match PeerId::from_bytes(&from) {
197+
let source = match PeerId::from_bytes(from) {
198198
Ok(v) => v,
199199
Err(_) => {
200200
debug!("Signature verification failed: Invalid Peer Id");
@@ -214,8 +214,8 @@ impl GossipsubCodec {
214214
// obtained from the inlined source peer_id.
215215
let public_key = match message
216216
.key
217-
.as_ref()
218-
.map(|key| PublicKey::from_protobuf_encoding(&key))
217+
.as_deref()
218+
.map(PublicKey::from_protobuf_encoding)
219219
{
220220
Some(Ok(key)) => key,
221221
_ => match PublicKey::from_protobuf_encoding(&source.to_bytes()[2..]) {

protocols/kad/src/handler.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -803,16 +803,12 @@ fn advance_substream<TUserData>(
803803
true,
804804
),
805805
Err(error) => {
806-
let event = if let Some(user_data) = user_data {
807-
Some(ProtocolsHandlerEvent::Custom(
808-
KademliaHandlerEvent::QueryError {
809-
error: KademliaHandlerQueryErr::Io(error),
810-
user_data,
811-
},
812-
))
813-
} else {
814-
None
815-
};
806+
let event = user_data.map(|user_data| {
807+
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
808+
error: KademliaHandlerQueryErr::Io(error),
809+
user_data,
810+
})
811+
});
816812

817813
(None, event, false)
818814
}
@@ -823,16 +819,12 @@ fn advance_substream<TUserData>(
823819
false,
824820
),
825821
Poll::Ready(Err(error)) => {
826-
let event = if let Some(user_data) = user_data {
827-
Some(ProtocolsHandlerEvent::Custom(
828-
KademliaHandlerEvent::QueryError {
829-
error: KademliaHandlerQueryErr::Io(error),
830-
user_data,
831-
},
832-
))
833-
} else {
834-
None
835-
};
822+
let event = user_data.map(|user_data| {
823+
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
824+
error: KademliaHandlerQueryErr::Io(error),
825+
user_data,
826+
})
827+
});
836828

837829
(None, event, false)
838830
}
@@ -857,16 +849,12 @@ fn advance_substream<TUserData>(
857849
false,
858850
),
859851
Poll::Ready(Err(error)) => {
860-
let event = if let Some(user_data) = user_data {
861-
Some(ProtocolsHandlerEvent::Custom(
862-
KademliaHandlerEvent::QueryError {
863-
error: KademliaHandlerQueryErr::Io(error),
864-
user_data,
865-
},
866-
))
867-
} else {
868-
None
869-
};
852+
let event = user_data.map(|user_data| {
853+
ProtocolsHandlerEvent::Custom(KademliaHandlerEvent::QueryError {
854+
error: KademliaHandlerQueryErr::Io(error),
855+
user_data,
856+
})
857+
});
870858

871859
(None, event, false)
872860
}

protocols/kad/src/kbucket/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ where
201201
let (node, status, _pos) = self
202202
.0
203203
.bucket
204-
.remove(&self.0.key)
204+
.remove(self.0.key)
205205
.expect("We can only build a PresentEntry if the entry is in the bucket; QED");
206206
EntryView { node, status }
207207
}

0 commit comments

Comments
 (0)