Skip to content

Commit 4e7ff3e

Browse files
jxsdariusc93
andauthored
chore(ci): address clippy beta lints (#5649)
Co-authored-by: Darius Clark <[email protected]>
1 parent c7e8129 commit 4e7ff3e

File tree

17 files changed

+29
-36
lines changed

17 files changed

+29
-36
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

identity/src/peer_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'de> Deserialize<'de> for PeerId {
191191

192192
struct PeerIdVisitor;
193193

194-
impl<'de> Visitor<'de> for PeerIdVisitor {
194+
impl Visitor<'_> for PeerIdVisitor {
195195
type Value = PeerId;
196196

197197
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {

identity/src/rsa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct Asn1RawOid<'a> {
149149
object: DerObject<'a>,
150150
}
151151

152-
impl<'a> Asn1RawOid<'a> {
152+
impl Asn1RawOid<'_> {
153153
/// The underlying OID as byte literal.
154154
pub(crate) fn oid(&self) -> &[u8] {
155155
self.object.value()
@@ -169,7 +169,7 @@ impl<'a> DerTypeView<'a> for Asn1RawOid<'a> {
169169
}
170170
}
171171

172-
impl<'a> DerEncodable for Asn1RawOid<'a> {
172+
impl DerEncodable for Asn1RawOid<'_> {
173173
fn encode<S: Sink>(&self, sink: &mut S) -> Result<(), Asn1DerError> {
174174
self.object.encode(sink)
175175
}

misc/quick-protobuf-codec/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a> BytesMutWriterBackend<'a> {
120120
}
121121
}
122122

123-
impl<'a> WriterBackend for BytesMutWriterBackend<'a> {
123+
impl WriterBackend for BytesMutWriterBackend<'_> {
124124
fn pb_write_u8(&mut self, x: u8) -> quick_protobuf::Result<()> {
125125
self.dst.put_u8(x);
126126

muxers/test-harness/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ enum Event {
206206
ProtocolComplete,
207207
}
208208

209-
impl<'m, M> Stream for Harness<'m, M>
209+
impl<M> Stream for Harness<'_, M>
210210
where
211211
M: StreamMuxer + Unpin,
212212
{

protocols/autonat/src/v1/behaviour/as_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) struct AsClient<'a> {
9898
pub(crate) other_candidates: &'a HashSet<Multiaddr>,
9999
}
100100

101-
impl<'a> HandleInnerEvent for AsClient<'a> {
101+
impl HandleInnerEvent for AsClient<'_> {
102102
fn handle_event(
103103
&mut self,
104104
event: request_response::Event<DialRequest, DialResponse>,
@@ -179,7 +179,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> {
179179
}
180180
}
181181

182-
impl<'a> AsClient<'a> {
182+
impl AsClient<'_> {
183183
pub(crate) fn poll_auto_probe(&mut self, cx: &mut Context<'_>) -> Poll<OutboundProbeEvent> {
184184
match self.schedule_probe.poll_unpin(cx) {
185185
Poll::Ready(()) => {

protocols/autonat/src/v1/behaviour/as_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(crate) struct AsServer<'a> {
9191
>,
9292
}
9393

94-
impl<'a> HandleInnerEvent for AsServer<'a> {
94+
impl HandleInnerEvent for AsServer<'_> {
9595
fn handle_event(
9696
&mut self,
9797
event: request_response::Event<DialRequest, DialResponse>,
@@ -208,7 +208,7 @@ impl<'a> HandleInnerEvent for AsServer<'a> {
208208
}
209209
}
210210

211-
impl<'a> AsServer<'a> {
211+
impl AsServer<'_> {
212212
pub(crate) fn on_outbound_connection(
213213
&mut self,
214214
peer: &PeerId,

protocols/gossipsub/src/backoff.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ pub(crate) struct BackoffStorage {
4848

4949
impl BackoffStorage {
5050
fn heartbeats(d: &Duration, heartbeat_interval: &Duration) -> usize {
51-
((d.as_nanos() + heartbeat_interval.as_nanos() - 1) / heartbeat_interval.as_nanos())
52-
as usize
51+
d.as_nanos().div_ceil(heartbeat_interval.as_nanos()) as usize
5352
}
5453

5554
pub(crate) fn new(

protocols/kad/src/behaviour.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,7 @@ pub struct QueryMut<'a> {
33613361
query: &'a mut Query,
33623362
}
33633363

3364-
impl<'a> QueryMut<'a> {
3364+
impl QueryMut<'_> {
33653365
pub fn id(&self) -> QueryId {
33663366
self.query.id()
33673367
}
@@ -3391,7 +3391,7 @@ pub struct QueryRef<'a> {
33913391
query: &'a Query,
33923392
}
33933393

3394-
impl<'a> QueryRef<'a> {
3394+
impl QueryRef<'_> {
33953395
pub fn id(&self) -> QueryId {
33963396
self.query.id()
33973397
}

protocols/ping/src/protocol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub const PROTOCOL_NAME: StreamProtocol = StreamProtocol::new("/ipfs/ping/1.0.0"
4444
/// > Nagle's algorithm, delayed acks and similar configuration options
4545
/// > which can affect latencies especially on otherwise low-volume
4646
/// > connections.
47-
4847
const PING_SIZE: usize = 32;
4948

5049
/// Sends a ping and waits for the pong.

swarm/src/connection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub(crate) struct IncomingInfo<'a> {
516516
pub(crate) send_back_addr: &'a Multiaddr,
517517
}
518518

519-
impl<'a> IncomingInfo<'a> {
519+
impl IncomingInfo<'_> {
520520
/// Builds the [`ConnectedPoint`] corresponding to the incoming connection.
521521
pub(crate) fn create_connected_point(&self) -> ConnectedPoint {
522522
ConnectedPoint::Listener {

swarm/src/handler.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IO
226226
RemoteProtocolsChange(ProtocolsChange<'a>),
227227
}
228228

229-
impl<'a, IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'a, IP, OP, IOI, OOI>
229+
impl<IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'_, IP, OP, IOI, OOI>
230230
where
231231
IP: InboundUpgradeSend + fmt::Debug,
232232
IP::Output: fmt::Debug,
@@ -262,8 +262,8 @@ where
262262
}
263263
}
264264

265-
impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI>
266-
ConnectionEvent<'a, IP, OP, IOI, OOI>
265+
impl<IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI>
266+
ConnectionEvent<'_, IP, OP, IOI, OOI>
267267
{
268268
/// Whether the event concerns an outbound stream.
269269
pub fn is_outbound(&self) -> bool {

transports/noise/src/io/handshake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ where
7373
/// will be sent and received on the given I/O resource and using the
7474
/// provided session for cryptographic operations according to the chosen
7575
/// Noise handshake pattern.
76-
7776
pub(crate) fn new(
7877
io: T,
7978
session: snow::HandshakeState,

transports/websocket-websys/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl libp2p_core::Transport for Transport {
9696
return Err(TransportError::MultiaddrNotSupported(addr));
9797
}
9898

99-
let url = extract_websocket_url(&addr)
100-
.ok_or_else(|| TransportError::MultiaddrNotSupported(addr))?;
99+
let url =
100+
extract_websocket_url(&addr).ok_or(TransportError::MultiaddrNotSupported(addr))?;
101101

102102
Ok(async move {
103103
let socket = match WebSocket::new(&url) {

transports/websocket/src/framed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub(crate) enum WsListenProto<'a> {
442442
TlsWs(Cow<'a, str>),
443443
}
444444

445-
impl<'a> WsListenProto<'a> {
445+
impl WsListenProto<'_> {
446446
pub(crate) fn append_on_addr(&self, addr: &mut Multiaddr) {
447447
match self {
448448
WsListenProto::Ws(path) => {

transports/webtransport-websys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ libp2p-identity = { workspace = true }
2121
libp2p-noise = { workspace = true }
2222
multiaddr = { workspace = true }
2323
multihash = { workspace = true }
24+
once_cell = "1.19.0"
2425
send_wrapper = { version = "0.6.0", features = ["futures"] }
2526
thiserror = "1.0.61"
2627
tracing = { workspace = true }

transports/webtransport-websys/src/utils.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
use js_sys::{Promise, Reflect};
2+
use once_cell::sync::Lazy;
23
use send_wrapper::SendWrapper;
34
use std::io;
45
use wasm_bindgen::{JsCast, JsValue};
56

67
use crate::Error;
78

9+
type Closure = wasm_bindgen::closure::Closure<dyn FnMut(JsValue)>;
10+
static DO_NOTHING: Lazy<SendWrapper<Closure>> = Lazy::new(|| {
11+
let cb = Closure::new(|_| {});
12+
SendWrapper::new(cb)
13+
});
14+
815
/// Properly detach a promise.
916
///
1017
/// A promise always runs in the background, however if you don't await it,
@@ -13,22 +20,9 @@ use crate::Error;
1320
//
1421
// Ref: https://github.com/typescript-eslint/typescript-eslint/blob/391a6702c0a9b5b3874a7a27047f2a721f090fb6/packages/eslint-plugin/docs/rules/no-floating-promises.md
1522
pub(crate) fn detach_promise(promise: Promise) {
16-
type Closure = wasm_bindgen::closure::Closure<dyn FnMut(JsValue)>;
17-
static mut DO_NOTHING: Option<SendWrapper<Closure>> = None;
18-
19-
// Allocate Closure only once and reuse it
20-
let do_nothing = unsafe {
21-
if DO_NOTHING.is_none() {
22-
let cb = Closure::new(|_| {});
23-
DO_NOTHING = Some(SendWrapper::new(cb));
24-
}
25-
26-
DO_NOTHING.as_deref().unwrap()
27-
};
28-
2923
// Avoid having "floating" promise and ignore any errors.
3024
// After `catch` promise is allowed to be dropped.
31-
let _ = promise.catch(do_nothing);
25+
let _ = promise.catch(&DO_NOTHING);
3226
}
3327

3428
/// Typecasts a JavaScript type.

0 commit comments

Comments
 (0)