Skip to content

Commit

Permalink
chore: Implement latest clippy warnings (libp2p#3220)
Browse files Browse the repository at this point in the history
As I do frequently, I corrected for the latest clippy warnings. This will make sure the CI won't complain in the future. We could automate this btw and maybe run the nightly version of clippy.
  • Loading branch information
umgefahren authored Dec 14, 2022
1 parent 76592e0 commit 4a2d8c7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions examples/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);
println!("Local peer id: {local_peer_id:?}");

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1)
Expand All @@ -88,9 +88,9 @@ async fn main() -> Result<(), Box<dyn Error>> {

loop {
match swarm.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {:?}", address),
SwarmEvent::Behaviour(event) => println!("{:?}", event),
e => println!("{:?}", e),
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
SwarmEvent::Behaviour(event) => println!("{event:?}"),
e => println!("{e:?}"),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {:?}", local_peer_id);
println!("Local peer id: {local_peer_id:?}");

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1)
Expand All @@ -72,9 +72,9 @@ async fn main() -> Result<(), Box<dyn Error>> {

loop {
match swarm.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {:?}", address),
SwarmEvent::Behaviour(event) => println!("{:?}", event),
e => println!("{:?}", e),
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
SwarmEvent::Behaviour(event) => println!("{event:?}"),
e => println!("{e:?}"),
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async fn test_auto_probe() {
assert!(peer.is_none());
assert_eq!(error, OutboundProbeError::NoAddresses);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

assert_eq!(client.behaviour().nat_status(), NatStatus::Unknown);
Expand All @@ -140,7 +140,7 @@ async fn test_auto_probe() {
assert_eq!(peer, server_id);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

match next_event(&mut client).await {
Expand All @@ -156,15 +156,15 @@ async fn test_auto_probe() {
OutboundProbeError::Response(ResponseError::DialError)
);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

match next_event(&mut client).await {
Event::StatusChanged { old, new } => {
assert_eq!(old, NatStatus::Unknown);
assert_eq!(new, NatStatus::Private);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

assert_eq!(client.behaviour().confidence(), 0);
Expand All @@ -186,7 +186,7 @@ async fn test_auto_probe() {
assert_eq!(peer, server_id);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

let mut had_connection_event = false;
Expand Down Expand Up @@ -216,7 +216,7 @@ async fn test_auto_probe() {
SwarmEvent::IncomingConnection { .. }
| SwarmEvent::NewListenAddr { .. }
| SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
}

Expand All @@ -230,7 +230,7 @@ async fn test_auto_probe() {
} if endpoint.is_listener() => {
assert_eq!(peer_id, server_id);
}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ async fn test_confidence() {
assert_eq!(peer, server_id);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

match next_event(&mut client).await {
Expand All @@ -302,12 +302,12 @@ async fn test_confidence() {
);
(peer.unwrap(), probe_id)
}
other => panic!("Unexpected Outbound Event: {:?}", other),
other => panic!("Unexpected Outbound Event: {other:?}"),
};
assert_eq!(peer, server_id);
assert_eq!(probe_id, id);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

// Confidence should increase each iteration up to MAX_CONFIDENCE
Expand All @@ -326,7 +326,7 @@ async fn test_confidence() {
assert_eq!(old, NatStatus::Unknown);
assert_eq!(new.is_public(), test_public);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ async fn test_throttle_server_period() {
}
Event::OutboundProbe(OutboundProbeEvent::Request { .. }) => {}
Event::OutboundProbe(OutboundProbeEvent::Response { .. }) => {}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
}

Expand All @@ -386,7 +386,7 @@ async fn test_throttle_server_period() {
assert!(peer.is_none());
assert_eq!(error, OutboundProbeError::NoServer);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
assert_eq!(client.behaviour().confidence(), 0);
};
Expand Down Expand Up @@ -431,14 +431,14 @@ async fn test_use_connected_as_server() {
Event::OutboundProbe(OutboundProbeEvent::Request { peer, .. }) => {
assert_eq!(peer, server_id);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

match next_event(&mut client).await {
Event::OutboundProbe(OutboundProbeEvent::Response { peer, .. }) => {
assert_eq!(peer, server_id);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
};

Expand Down Expand Up @@ -487,7 +487,7 @@ async fn test_outbound_failure() {
}
Event::OutboundProbe(OutboundProbeEvent::Request { .. }) => {}
Event::OutboundProbe(OutboundProbeEvent::Response { .. }) => {}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
}

Expand All @@ -511,7 +511,7 @@ async fn test_outbound_failure() {
}) => {
assert!(inactive_ids.contains(&peer));
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
}
};
Expand Down Expand Up @@ -563,7 +563,7 @@ async fn test_global_ips_config() {
Event::OutboundProbe(OutboundProbeEvent::Error { error, .. }) => {
assert!(matches!(error, OutboundProbeError::NoServer))
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
};

Expand Down
30 changes: 15 additions & 15 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async fn test_dial_back() {
SwarmEvent::IncomingConnection { .. }
| SwarmEvent::NewListenAddr { .. }
| SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
};
let expect_addr = Multiaddr::empty()
Expand All @@ -185,7 +185,7 @@ async fn test_dial_back() {
assert_eq!(addresses[0], expect_addr);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

loop {
Expand All @@ -209,7 +209,7 @@ async fn test_dial_back() {
}
SwarmEvent::Dialing(peer) => assert_eq!(peer, client_id),
SwarmEvent::NewListenAddr { .. } | SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
}

Expand All @@ -223,7 +223,7 @@ async fn test_dial_back() {
assert_eq!(peer, client_id);
assert_eq!(address, expect_addr);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
};

Expand All @@ -241,7 +241,7 @@ async fn test_dial_error() {
assert_eq!(peer, client_id);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

loop {
Expand All @@ -253,7 +253,7 @@ async fn test_dial_error() {
}
SwarmEvent::Dialing(peer) => assert_eq!(peer, client_id),
SwarmEvent::NewListenAddr { .. } | SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
}

Expand All @@ -267,7 +267,7 @@ async fn test_dial_error() {
assert_eq!(peer, client_id);
assert_eq!(error, InboundProbeError::Response(ResponseError::DialError));
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}
};

Expand Down Expand Up @@ -295,7 +295,7 @@ async fn test_throttle_global_max() {
Event::InboundProbe(InboundProbeEvent::Request { peer, probe_id, .. }) => {
(probe_id, peer)
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

loop {
Expand All @@ -313,7 +313,7 @@ async fn test_throttle_global_max() {
assert_eq!(first_peer_id, peer);
assert_eq!(first_probe_id, probe_id);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};
}
};
Expand All @@ -340,15 +340,15 @@ async fn test_throttle_peer_max() {
assert_eq!(client_id, peer);
probe_id
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

match next_event(&mut server).await {
Event::InboundProbe(InboundProbeEvent::Response { peer, probe_id, .. }) => {
assert_eq!(peer, client_id);
assert_eq!(probe_id, first_probe_id);
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
}

match next_event(&mut server).await {
Expand All @@ -364,7 +364,7 @@ async fn test_throttle_peer_max() {
InboundProbeError::Response(ResponseError::DialRefused)
)
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};
};

Expand Down Expand Up @@ -393,7 +393,7 @@ async fn test_dial_multiple_addr() {
assert_eq!(client_id, peer);
addresses
}
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};

loop {
Expand All @@ -417,7 +417,7 @@ async fn test_dial_multiple_addr() {
}
SwarmEvent::Dialing(peer) => assert_eq!(peer, client_id),
SwarmEvent::NewListenAddr { .. } | SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
other => panic!("Unexpected swarm event: {other:?}."),
}
}
};
Expand All @@ -444,7 +444,7 @@ async fn test_global_ips_config() {
error,
InboundProbeError::Response(ResponseError::DialRefused)
)),
other => panic!("Unexpected behaviour event: {:?}.", other),
other => panic!("Unexpected behaviour event: {other:?}."),
};
};

Expand Down

0 comments on commit 4a2d8c7

Please sign in to comment.