Skip to content

Commit

Permalink
.cargo: Run clippy on ALL the source files (libp2p#2949)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger authored Oct 4, 2022
1 parent cc9792b commit 4c0748f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
1 change: 1 addition & 0 deletions examples/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl Behaviour {
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
AutoNat(autonat::Event),
Identify(identify::Event),
Expand Down
1 change: 1 addition & 0 deletions examples/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl Behaviour {
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
AutoNat(autonat::Event),
Identify(identify::Event),
Expand Down
42 changes: 17 additions & 25 deletions tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ async fn spawn_server(kill: oneshot::Receiver<()>) -> (PeerId, Multiaddr) {
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
let addr = loop {
match server.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => break address,
_ => {}
if let SwarmEvent::NewListenAddr { address, .. } = server.select_next_some().await {
break address;
};
};
tx.send((peer_id, addr)).unwrap();
Expand All @@ -78,11 +77,8 @@ async fn spawn_server(kill: oneshot::Receiver<()>) -> (PeerId, Multiaddr) {

async fn next_event(swarm: &mut Swarm<Behaviour>) -> Event {
loop {
match swarm.select_next_some().await {
SwarmEvent::Behaviour(event) => {
break event;
}
_ => {}
if let SwarmEvent::Behaviour(event) = swarm.select_next_some().await {
break event;
}
}
}
Expand Down Expand Up @@ -177,9 +173,8 @@ async fn test_auto_probe() {
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { .. } => break,
_ => {}
if let SwarmEvent::NewListenAddr { .. } = client.select_next_some().await {
break;
}
}

Expand Down Expand Up @@ -269,14 +264,13 @@ async fn test_confidence() {
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { .. } => break,
_ => {}
if let SwarmEvent::NewListenAddr { .. } = client.select_next_some().await {
break;
}
}
} else {
let unreachable_addr: Multiaddr = "/ip4/127.0.0.1/tcp/42".parse().unwrap();
client.add_external_address(unreachable_addr.clone(), AddressScore::Infinite);
client.add_external_address(unreachable_addr, AddressScore::Infinite);
}

for i in 0..MAX_CONFIDENCE + 1 {
Expand Down Expand Up @@ -357,9 +351,8 @@ async fn test_throttle_server_period() {
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { .. } => break,
_ => {}
if let SwarmEvent::NewListenAddr { .. } = client.select_next_some().await {
break;
}
}

Expand Down Expand Up @@ -477,9 +470,8 @@ async fn test_outbound_failure() {
.unwrap();

loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { .. } => break,
_ => {}
if let SwarmEvent::NewListenAddr { .. } = client.select_next_some().await {
break;
}
}
// First probe should be successful and flip status to public.
Expand All @@ -497,7 +489,8 @@ async fn test_outbound_failure() {
}

let inactive = servers.split_off(1);
// Drop the handles of the inactive servers to kill them.

#[allow(clippy::needless_collect)] // Drop the handles of the inactive servers to kill them.
let inactive_ids: Vec<_> = inactive.into_iter().map(|(id, _handle)| id).collect();

// Expect to retry on outbound failure
Expand Down Expand Up @@ -541,9 +534,8 @@ async fn test_global_ips_config() {
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { .. } => break,
_ => {}
if let SwarmEvent::NewListenAddr { .. } = client.select_next_some().await {
break;
}
}

Expand Down
26 changes: 9 additions & 17 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ async fn init_server(config: Option<Config>) -> (Swarm<Behaviour>, PeerId, Multi
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
let addr = loop {
match server.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => break address,
_ => {}
if let SwarmEvent::NewListenAddr { address, .. } = server.select_next_some().await {
break address;
};
};
(server, peer_id, addr)
Expand Down Expand Up @@ -91,12 +90,9 @@ async fn spawn_client(
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
loop {
match client.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => {
addr = Some(address);
break;
}
_ => {}
if let SwarmEvent::NewListenAddr { address, .. } = client.select_next_some().await {
addr = Some(address);
break;
};
}
}
Expand All @@ -119,11 +115,8 @@ async fn spawn_client(

async fn next_event(swarm: &mut Swarm<Behaviour>) -> Event {
loop {
match swarm.select_next_some().await {
SwarmEvent::Behaviour(event) => {
break event;
}
_ => {}
if let SwarmEvent::Behaviour(event) = swarm.select_next_some().await {
break event;
}
}
}
Expand Down Expand Up @@ -161,9 +154,8 @@ async fn test_dial_back() {
} => {
assert_eq!(peer_id, client_id);
let observed_client_ip = loop {
match send_back_addr.pop().unwrap() {
Protocol::Ip4(ip4_addr) => break ip4_addr,
_ => {}
if let Protocol::Ip4(ip4_addr) = send_back_addr.pop().unwrap() {
break ip4_addr;
}
};
break observed_client_ip;
Expand Down

0 comments on commit 4c0748f

Please sign in to comment.