Skip to content

Commit

Permalink
chore(ci): address clippy beta lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Oct 26, 2024
1 parent 84c617f commit abe30e8
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion identity/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'de> Deserialize<'de> for PeerId {

struct PeerIdVisitor;

impl<'de> Visitor<'de> for PeerIdVisitor {
impl Visitor<'_> for PeerIdVisitor {
type Value = PeerId;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
4 changes: 2 additions & 2 deletions identity/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct Asn1RawOid<'a> {
object: DerObject<'a>,
}

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

impl<'a> DerEncodable for Asn1RawOid<'a> {
impl DerEncodable for Asn1RawOid<'_> {
fn encode<S: Sink>(&self, sink: &mut S) -> Result<(), Asn1DerError> {
self.object.encode(sink)
}
Expand Down
2 changes: 1 addition & 1 deletion misc/quick-protobuf-codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a> BytesMutWriterBackend<'a> {
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion muxers/test-harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ enum Event {
ProtocolComplete,
}

impl<'m, M> Stream for Harness<'m, M>
impl<M> Stream for Harness<'_, M>
where
M: StreamMuxer + Unpin,
{
Expand Down
4 changes: 2 additions & 2 deletions protocols/autonat/src/v1/behaviour/as_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) struct AsClient<'a> {
pub(crate) other_candidates: &'a HashSet<Multiaddr>,
}

impl<'a> HandleInnerEvent for AsClient<'a> {
impl HandleInnerEvent for AsClient<'_> {
fn handle_event(
&mut self,
event: request_response::Event<DialRequest, DialResponse>,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> {
}
}

impl<'a> AsClient<'a> {
impl AsClient<'_> {
pub(crate) fn poll_auto_probe(&mut self, cx: &mut Context<'_>) -> Poll<OutboundProbeEvent> {
match self.schedule_probe.poll_unpin(cx) {
Poll::Ready(()) => {
Expand Down
4 changes: 2 additions & 2 deletions protocols/autonat/src/v1/behaviour/as_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(crate) struct AsServer<'a> {
>,
}

impl<'a> HandleInnerEvent for AsServer<'a> {
impl HandleInnerEvent for AsServer<'_> {
fn handle_event(
&mut self,
event: request_response::Event<DialRequest, DialResponse>,
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<'a> HandleInnerEvent for AsServer<'a> {
}
}

impl<'a> AsServer<'a> {
impl AsServer<'_> {
pub(crate) fn on_outbound_connection(
&mut self,
peer: &PeerId,
Expand Down
3 changes: 1 addition & 2 deletions protocols/gossipsub/src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub(crate) struct BackoffStorage {

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

pub(crate) fn new(
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3361,7 +3361,7 @@ pub struct QueryMut<'a> {
query: &'a mut Query,
}

impl<'a> QueryMut<'a> {
impl QueryMut<'_> {
pub fn id(&self) -> QueryId {
self.query.id()
}
Expand Down Expand Up @@ -3391,7 +3391,7 @@ pub struct QueryRef<'a> {
query: &'a Query,
}

impl<'a> QueryRef<'a> {
impl QueryRef<'_> {
pub fn id(&self) -> QueryId {
self.query.id()
}
Expand Down
1 change: 0 additions & 1 deletion protocols/ping/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub const PROTOCOL_NAME: StreamProtocol = StreamProtocol::new("/ipfs/ping/1.0.0"
/// > Nagle's algorithm, delayed acks and similar configuration options
/// > which can affect latencies especially on otherwise low-volume
/// > connections.
const PING_SIZE: usize = 32;

/// Sends a ping and waits for the pong.
Expand Down
2 changes: 1 addition & 1 deletion swarm/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ pub(crate) struct IncomingInfo<'a> {
pub(crate) send_back_addr: &'a Multiaddr,
}

impl<'a> IncomingInfo<'a> {
impl IncomingInfo<'_> {
/// Builds the [`ConnectedPoint`] corresponding to the incoming connection.
pub(crate) fn create_connected_point(&self) -> ConnectedPoint {
ConnectedPoint::Listener {
Expand Down
6 changes: 3 additions & 3 deletions swarm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IO
RemoteProtocolsChange(ProtocolsChange<'a>),
}

impl<'a, IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'a, IP, OP, IOI, OOI>
impl<IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'_, IP, OP, IOI, OOI>
where
IP: InboundUpgradeSend + fmt::Debug,
IP::Output: fmt::Debug,
Expand Down Expand Up @@ -262,8 +262,8 @@ where
}
}

impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI>
ConnectionEvent<'a, IP, OP, IOI, OOI>
impl<IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI>
ConnectionEvent<'_, IP, OP, IOI, OOI>
{
/// Whether the event concerns an outbound stream.
pub fn is_outbound(&self) -> bool {
Expand Down
1 change: 0 additions & 1 deletion transports/noise/src/io/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ where
/// will be sent and received on the given I/O resource and using the
/// provided session for cryptographic operations according to the chosen
/// Noise handshake pattern.
pub(crate) fn new(
io: T,
session: snow::HandshakeState,
Expand Down
4 changes: 2 additions & 2 deletions transports/websocket-websys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl libp2p_core::Transport for Transport {
return Err(TransportError::MultiaddrNotSupported(addr));
}

let url = extract_websocket_url(&addr)
.ok_or_else(|| TransportError::MultiaddrNotSupported(addr))?;
let url =
extract_websocket_url(&addr).ok_or(TransportError::MultiaddrNotSupported(addr))?;

Ok(async move {
let socket = match WebSocket::new(&url) {
Expand Down
2 changes: 1 addition & 1 deletion transports/websocket/src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub(crate) enum WsListenProto<'a> {
TlsWs(Cow<'a, str>),
}

impl<'a> WsListenProto<'a> {
impl WsListenProto<'_> {
pub(crate) fn append_on_addr(&self, addr: &mut Multiaddr) {
match self {
WsListenProto::Ws(path) => {
Expand Down
1 change: 1 addition & 0 deletions transports/webtransport-websys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ libp2p-identity = { workspace = true }
libp2p-noise = { workspace = true }
multiaddr = { workspace = true }
multihash = { workspace = true }
once_cell = "1.19.0"
send_wrapper = { version = "0.6.0", features = ["futures"] }
thiserror = "1.0.61"
tracing = { workspace = true }
Expand Down
22 changes: 8 additions & 14 deletions transports/webtransport-websys/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use js_sys::{Promise, Reflect};
use once_cell::sync::Lazy;
use send_wrapper::SendWrapper;
use std::io;
use wasm_bindgen::{JsCast, JsValue};

use crate::Error;

type Closure = wasm_bindgen::closure::Closure<dyn FnMut(JsValue)>;
static DO_NOTHING: Lazy<SendWrapper<Closure>> = Lazy::new(|| {
let cb = Closure::new(|_| {});
SendWrapper::new(cb)
});

/// Properly detach a promise.
///
/// A promise always runs in the background, however if you don't await it,
Expand All @@ -13,22 +20,9 @@ use crate::Error;
//
// Ref: https://github.com/typescript-eslint/typescript-eslint/blob/391a6702c0a9b5b3874a7a27047f2a721f090fb6/packages/eslint-plugin/docs/rules/no-floating-promises.md
pub(crate) fn detach_promise(promise: Promise) {
type Closure = wasm_bindgen::closure::Closure<dyn FnMut(JsValue)>;
static mut DO_NOTHING: Option<SendWrapper<Closure>> = None;

// Allocate Closure only once and reuse it
let do_nothing = unsafe {
if DO_NOTHING.is_none() {
let cb = Closure::new(|_| {});
DO_NOTHING = Some(SendWrapper::new(cb));
}

DO_NOTHING.as_deref().unwrap()
};

// Avoid having "floating" promise and ignore any errors.
// After `catch` promise is allowed to be dropped.
let _ = promise.catch(do_nothing);
let _ = promise.catch(&DO_NOTHING);
}

/// Typecasts a JavaScript type.
Expand Down

0 comments on commit abe30e8

Please sign in to comment.