Skip to content

Commit 1e4e36c

Browse files
Make cargo clippy happy (#426)
Make `cargo clippy` & `cargo check` happy in default and `--all-features` configurations. This is needed due to stable toolchain update and clippy now discovering more issues than before in #422.
1 parent 784e774 commit 1e4e36c

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

src/crypto/tls/certificate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub struct VerificationError(#[from] pub(crate) webpki::Error);
126126
/// Internal function that only parses but does not verify the certificate.
127127
///
128128
/// Useful for testing but unsuitable for production.
129-
fn parse_unverified(der_input: &[u8]) -> Result<P2pCertificate, webpki::Error> {
129+
fn parse_unverified<'a>(der_input: &'a [u8]) -> Result<P2pCertificate<'a>, webpki::Error> {
130130
let x509 = X509Certificate::from_der(der_input)
131131
.map(|(_rest_input, x509)| x509)
132132
.map_err(|_| webpki::Error::BadDer)?;

src/transport/common/listener.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ impl GetSocketAddr for TcpAddress {
202202
}
203203

204204
/// WebSocket helper to convert between `Multiaddr` and `SocketAddr`.
205+
#[cfg(feature = "websocket")]
205206
pub struct WebSocketAddress;
206207

208+
#[cfg(feature = "websocket")]
207209
impl GetSocketAddr for WebSocketAddress {
208210
fn multiaddr_to_socket_address(
209211
address: &Multiaddr,
@@ -339,6 +341,7 @@ enum SocketListenerType {
339341
/// Listener for TCP.
340342
Tcp,
341343
/// Listener for WebSocket.
344+
#[cfg(feature = "websocket")]
342345
WebSocket,
343346
}
344347

@@ -406,6 +409,7 @@ fn multiaddr_to_socket_address(
406409

407410
match ty {
408411
SocketListenerType::Tcp => (),
412+
#[cfg(feature = "websocket")]
409413
SocketListenerType::WebSocket => {
410414
// verify that `/ws`/`/wss` is part of the multi address
411415
match iter.next() {
@@ -518,6 +522,7 @@ mod tests {
518522
.is_err());
519523
}
520524

525+
#[cfg(feature = "websocket")]
521526
#[test]
522527
fn parse_multiaddresses_websocket() {
523528
assert!(multiaddr_to_socket_address(
@@ -618,6 +623,7 @@ mod tests {
618623
.await;
619624
}
620625

626+
#[cfg(feature = "websocket")]
621627
#[tokio::test]
622628
async fn no_listeners_websocket() {
623629
let (mut listener, _, _) = SocketListener::new::<WebSocketAddress>(Vec::new(), true, false);
@@ -646,6 +652,7 @@ mod tests {
646652
assert!(res1.unwrap().is_ok() && res2.is_ok());
647653
}
648654

655+
#[cfg(feature = "websocket")]
649656
#[tokio::test]
650657
async fn one_listener_websocket() {
651658
let address: Multiaddr = "/ip6/::1/tcp/0/ws".parse().unwrap();
@@ -689,6 +696,7 @@ mod tests {
689696
assert!(res1.is_ok() && res2.is_ok());
690697
}
691698

699+
#[cfg(feature = "websocket")]
692700
#[tokio::test]
693701
async fn two_listeners_websocket() {
694702
let address1: Multiaddr = "/ip6/::1/tcp/0/ws".parse().unwrap();

src/transport/dummy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ pub(crate) struct DummyTransport {
4242

4343
impl DummyTransport {
4444
/// Create new [`DummyTransport`].
45-
#[cfg(test)]
4645
pub(crate) fn new() -> Self {
4746
Self {
4847
events: VecDeque::new(),
4948
}
5049
}
5150

5251
/// Inject event into `DummyTransport`.
53-
#[cfg(test)]
5452
pub(crate) fn inject_event(&mut self, event: TransportEvent) {
5553
self.events.push_back(event);
5654
}

src/transport/manager/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl Eq for AddressRecord {}
136136

137137
impl PartialOrd for AddressRecord {
138138
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
139-
Some(self.score.cmp(&other.score))
139+
Some(self.cmp(other))
140140
}
141141
}
142142

src/transport/manager/handle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ mod tests {
387387

388388
#[tokio::test]
389389
async fn tcp_unsupported() {
390-
let (mut handle, _rx) = make_transport_manager_handle();
390+
let (handle, _rx) = make_transport_manager_handle();
391391

392392
let address =
393393
"/dns4/google.com/tcp/24928/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy"
@@ -424,7 +424,7 @@ mod tests {
424424
#[cfg(feature = "websocket")]
425425
#[tokio::test]
426426
async fn websocket_unsupported() {
427-
let (mut handle, _rx) = make_transport_manager_handle();
427+
let (handle, _rx) = make_transport_manager_handle();
428428

429429
let address =
430430
"/dns4/google.com/tcp/24928/ws/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy"
@@ -462,7 +462,7 @@ mod tests {
462462
#[cfg(feature = "websocket")]
463463
#[tokio::test]
464464
async fn wss_unsupported() {
465-
let (mut handle, _rx) = make_transport_manager_handle();
465+
let (handle, _rx) = make_transport_manager_handle();
466466

467467
let address =
468468
"/dns4/google.com/tcp/24928/wss/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy"
@@ -500,7 +500,7 @@ mod tests {
500500
#[cfg(feature = "quic")]
501501
#[tokio::test]
502502
async fn quic_unsupported() {
503-
let (mut handle, _rx) = make_transport_manager_handle();
503+
let (handle, _rx) = make_transport_manager_handle();
504504

505505
let address =
506506
"/dns4/google.com/udp/24928/quic-v1/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy"

src/transport/manager/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,16 +1377,19 @@ mod tests {
13771377
(dial_address, connection_id)
13781378
}
13791379

1380+
#[cfg(feature = "websocket")]
13801381
struct MockTransport {
13811382
rx: tokio::sync::mpsc::Receiver<TransportEvent>,
13821383
}
13831384

1385+
#[cfg(feature = "websocket")]
13841386
impl MockTransport {
13851387
fn new(rx: tokio::sync::mpsc::Receiver<TransportEvent>) -> Self {
13861388
Self { rx }
13871389
}
13881390
}
13891391

1392+
#[cfg(feature = "websocket")]
13901393
impl Transport for MockTransport {
13911394
fn dial(&mut self, _connection_id: ConnectionId, _address: Multiaddr) -> crate::Result<()> {
13921395
Ok(())
@@ -1422,6 +1425,8 @@ mod tests {
14221425

14231426
fn cancel(&mut self, _connection_id: ConnectionId) {}
14241427
}
1428+
1429+
#[cfg(feature = "websocket")]
14251430
impl Stream for MockTransport {
14261431
type Item = TransportEvent;
14271432
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {

src/transport/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ pub mod webrtc;
3737
#[cfg(feature = "websocket")]
3838
pub mod websocket;
3939

40+
#[cfg(test)]
4041
pub(crate) mod dummy;
42+
4143
pub(crate) mod manager;
4244

4345
pub use manager::limits::{ConnectionLimitsConfig, ConnectionLimitsError};

0 commit comments

Comments
 (0)