Skip to content

Commit 06bc677

Browse files
chore: fix lint warnings introduced by beta clippy
Pull-Request: #4386.
1 parent 4284cae commit 06bc677

File tree

8 files changed

+33
-55
lines changed

8 files changed

+33
-55
lines changed

muxers/mplex/src/io.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ where
143143
}
144144

145145
/// Flushes the underlying I/O stream.
146-
pub(crate) fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
146+
pub(crate) fn poll_flush(&mut self, cx: &Context<'_>) -> Poll<io::Result<()>> {
147147
match &self.status {
148148
Status::Closed => return Poll::Ready(Ok(())),
149149
Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))),
@@ -169,7 +169,7 @@ where
169169
/// > **Note**: No `Close` or `Reset` frames are sent on open substreams
170170
/// > before closing the underlying connection. However, the connection
171171
/// > close implies a flush of any frames already sent.
172-
pub(crate) fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
172+
pub(crate) fn poll_close(&mut self, cx: &Context<'_>) -> Poll<io::Result<()>> {
173173
match &self.status {
174174
Status::Closed => return Poll::Ready(Ok(())),
175175
Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))),
@@ -208,10 +208,7 @@ where
208208
/// [`MaxBufferBehaviour::Block`] is used, this method is blocked
209209
/// (i.e. `Pending`) on some task reading from the substream whose
210210
/// buffer is full.
211-
pub(crate) fn poll_next_stream(
212-
&mut self,
213-
cx: &mut Context<'_>,
214-
) -> Poll<io::Result<LocalStreamId>> {
211+
pub(crate) fn poll_next_stream(&mut self, cx: &Context<'_>) -> Poll<io::Result<LocalStreamId>> {
215212
self.guard_open()?;
216213

217214
// Try to read from the buffer first.
@@ -252,10 +249,7 @@ where
252249
}
253250

254251
/// Creates a new (outbound) substream, returning the allocated stream ID.
255-
pub(crate) fn poll_open_stream(
256-
&mut self,
257-
cx: &mut Context<'_>,
258-
) -> Poll<io::Result<LocalStreamId>> {
252+
pub(crate) fn poll_open_stream(&mut self, cx: &Context<'_>) -> Poll<io::Result<LocalStreamId>> {
259253
self.guard_open()?;
260254

261255
// Check the stream limits.
@@ -374,7 +368,7 @@ where
374368
/// Writes data to a substream.
375369
pub(crate) fn poll_write_stream(
376370
&mut self,
377-
cx: &mut Context<'_>,
371+
cx: &Context<'_>,
378372
id: LocalStreamId,
379373
buf: &[u8],
380374
) -> Poll<io::Result<usize>> {
@@ -424,7 +418,7 @@ where
424418
/// Inbound substreams received in excess of that limit are immediately reset.
425419
pub(crate) fn poll_read_stream(
426420
&mut self,
427-
cx: &mut Context<'_>,
421+
cx: &Context<'_>,
428422
id: LocalStreamId,
429423
) -> Poll<io::Result<Option<Bytes>>> {
430424
self.guard_open()?;
@@ -516,7 +510,7 @@ where
516510
/// > the underlying I/O stream is already closed.
517511
pub(crate) fn poll_flush_stream(
518512
&mut self,
519-
cx: &mut Context<'_>,
513+
cx: &Context<'_>,
520514
id: LocalStreamId,
521515
) -> Poll<io::Result<()>> {
522516
self.guard_open()?;
@@ -532,7 +526,7 @@ where
532526
/// > **Note**: As opposed to `poll_close()`, a flush it not implied.
533527
pub(crate) fn poll_close_stream(
534528
&mut self,
535-
cx: &mut Context<'_>,
529+
cx: &Context<'_>,
536530
id: LocalStreamId,
537531
) -> Poll<io::Result<()>> {
538532
self.guard_open()?;
@@ -587,7 +581,7 @@ where
587581
///
588582
/// The frame is only constructed if the underlying sink is ready to
589583
/// send another frame.
590-
fn poll_send_frame<F>(&mut self, cx: &mut Context<'_>, frame: F) -> Poll<io::Result<()>>
584+
fn poll_send_frame<F>(&mut self, cx: &Context<'_>, frame: F) -> Poll<io::Result<()>>
591585
where
592586
F: FnOnce() -> Frame<LocalStreamId>,
593587
{
@@ -613,7 +607,7 @@ where
613607
/// frames for any substream.
614608
fn poll_read_frame(
615609
&mut self,
616-
cx: &mut Context<'_>,
610+
cx: &Context<'_>,
617611
stream_id: Option<LocalStreamId>,
618612
) -> Poll<io::Result<Frame<RemoteStreamId>>> {
619613
// Try to send pending frames, if there are any, without blocking,
@@ -822,7 +816,7 @@ where
822816
}
823817

824818
/// Sends pending frames, without flushing.
825-
fn send_pending_frames(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
819+
fn send_pending_frames(&mut self, cx: &Context<'_>) -> Poll<io::Result<()>> {
826820
while let Some(frame) = self.pending_frames.pop_back() {
827821
if self.poll_send_frame(cx, || frame.clone())?.is_pending() {
828822
self.pending_frames.push_back(frame);

protocols/gossipsub/src/backoff.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ impl BackoffStorage {
8686
backoffs_by_heartbeat[index].insert(pair);
8787
HeartbeatIndex(index)
8888
};
89-
match self
90-
.backoffs
91-
.entry(topic.clone())
92-
.or_insert_with(HashMap::new)
93-
.entry(*peer)
94-
{
89+
match self.backoffs.entry(topic.clone()).or_default().entry(*peer) {
9590
Entry::Occupied(mut o) => {
9691
let (backoff, index) = o.get();
9792
if backoff < &instant {

protocols/gossipsub/src/behaviour.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,7 @@ where
10201020
"JOIN: Inserting {:?} random peers into the mesh",
10211021
new_peers.len()
10221022
);
1023-
let mesh_peers = self
1024-
.mesh
1025-
.entry(topic_hash.clone())
1026-
.or_insert_with(Default::default);
1023+
let mesh_peers = self.mesh.entry(topic_hash.clone()).or_default();
10271024
mesh_peers.extend(new_peers);
10281025
}
10291026

@@ -1962,10 +1959,7 @@ where
19621959
for subscription in filtered_topics {
19631960
// get the peers from the mapping, or insert empty lists if the topic doesn't exist
19641961
let topic_hash = &subscription.topic_hash;
1965-
let peer_list = self
1966-
.topic_peers
1967-
.entry(topic_hash.clone())
1968-
.or_insert_with(Default::default);
1962+
let peer_list = self.topic_peers.entry(topic_hash.clone()).or_default();
19691963

19701964
match subscription.action {
19711965
SubscriptionAction::Subscribe => {
@@ -2874,10 +2868,7 @@ where
28742868
peer: PeerId,
28752869
control: ControlAction,
28762870
) {
2877-
control_pool
2878-
.entry(peer)
2879-
.or_insert_with(Vec::new)
2880-
.push(control);
2871+
control_pool.entry(peer).or_default().push(control);
28812872
}
28822873

28832874
/// Takes each control action mapping and turns it into a message

protocols/gossipsub/src/gossip_promises.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl GossipPromises {
4848
// If a promise for this message id and peer already exists we don't update the expiry!
4949
self.promises
5050
.entry(message_id.clone())
51-
.or_insert_with(HashMap::new)
51+
.or_default()
5252
.entry(peer)
5353
.or_insert(expires);
5454
}

protocols/gossipsub/src/peer_score.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,7 @@ impl PeerScore {
454454

455455
// Insert the ip
456456
peer_stats.known_ips.insert(ip);
457-
self.peer_ips
458-
.entry(ip)
459-
.or_insert_with(HashSet::new)
460-
.insert(*peer_id);
457+
self.peer_ips.entry(ip).or_default().insert(*peer_id);
461458
}
462459

463460
/// Removes an ip from a peer
@@ -570,9 +567,7 @@ impl PeerScore {
570567
topic_hash: &TopicHash,
571568
) {
572569
// adds an empty record with the message id
573-
self.deliveries
574-
.entry(msg_id.clone())
575-
.or_insert_with(DeliveryRecord::default);
570+
self.deliveries.entry(msg_id.clone()).or_default();
576571

577572
if let Some(callback) = self.message_delivery_time_callback {
578573
if self
@@ -595,10 +590,7 @@ impl PeerScore {
595590
) {
596591
self.mark_first_message_delivery(from, topic_hash);
597592

598-
let record = self
599-
.deliveries
600-
.entry(msg_id.clone())
601-
.or_insert_with(DeliveryRecord::default);
593+
let record = self.deliveries.entry(msg_id.clone()).or_default();
602594

603595
// this should be the first delivery trace
604596
if record.status != DeliveryStatus::Unknown {
@@ -649,10 +641,7 @@ impl PeerScore {
649641
}
650642

651643
let peers: Vec<_> = {
652-
let record = self
653-
.deliveries
654-
.entry(msg_id.clone())
655-
.or_insert_with(DeliveryRecord::default);
644+
let record = self.deliveries.entry(msg_id.clone()).or_default();
656645

657646
// Multiple peers can now reject the same message as we track which peers send us the
658647
// message. If we have already updated the status, return.
@@ -686,10 +675,7 @@ impl PeerScore {
686675
msg_id: &MessageId,
687676
topic_hash: &TopicHash,
688677
) {
689-
let record = self
690-
.deliveries
691-
.entry(msg_id.clone())
692-
.or_insert_with(DeliveryRecord::default);
678+
let record = self.deliveries.entry(msg_id.clone()).or_default();
693679

694680
if record.peers.get(from).is_some() {
695681
// we have already seen this duplicate!

protocols/gossipsub/src/time_cache.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ where
9999
Entry::Vacant(entry) => entry.insert(default()),
100100
}
101101
}
102+
pub(crate) fn or_default(self) -> &'a mut V
103+
where
104+
V: Default,
105+
{
106+
match self {
107+
Entry::Occupied(entry) => entry.into_mut(),
108+
Entry::Vacant(entry) => entry.insert(V::default()),
109+
}
110+
}
102111
}
103112

104113
impl<Key, Value> TimeCache<Key, Value>

transports/quic/tests/smoke.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ async fn open_outbound_streams<P: Provider + Spawn, const BUFFER_SIZE: usize>(
730730
}
731731

732732
/// Helper function for driving two transports until they established a connection.
733+
#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive.
733734
async fn connect(
734735
listener: &mut Boxed<(PeerId, StreamMuxerBox)>,
735736
dialer: &mut Boxed<(PeerId, StreamMuxerBox)>,

wasm-tests/webtransport-tests/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,14 @@ async fn fetch_server_addr() -> Multiaddr {
338338
.unwrap()
339339
}
340340

341+
#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive.
341342
async fn create_stream(conn: &mut Connection) -> Stream {
342343
poll_fn(|cx| Pin::new(&mut *conn).poll_outbound(cx))
343344
.await
344345
.unwrap()
345346
}
346347

348+
#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive.
347349
async fn incoming_stream(conn: &mut Connection) -> Stream {
348350
let mut stream = poll_fn(|cx| Pin::new(&mut *conn).poll_inbound(cx))
349351
.await

0 commit comments

Comments
 (0)