Skip to content

Commit

Permalink
Fix most clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Sep 28, 2022
1 parent 6ff6acd commit 345d986
Show file tree
Hide file tree
Showing 34 changed files with 683 additions and 828 deletions.
8 changes: 4 additions & 4 deletions core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ mod tests {

#[test]
fn extract_peer_id_from_multi_address() {
let address =
"/memory/1234/p2p/12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc".to_string()
.parse()
.unwrap();
let address = "/memory/1234/p2p/12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc"
.to_string()
.parse()
.unwrap();

let peer_id = PeerId::try_from_multiaddr(&address).unwrap();

Expand Down
7 changes: 4 additions & 3 deletions misc/multistream-select/tests/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ fn transport_upgrade() {
let addr = addr_receiver.await.unwrap();
dialer.dial(addr).unwrap();
futures::future::poll_fn(move |cx| loop {
match ready!(dialer.poll_next_unpin(cx)).unwrap() {
SwarmEvent::ConnectionEstablished { .. } => return Poll::Ready(()),
_ => {}
if let SwarmEvent::ConnectionEstablished { .. } =
ready!(dialer.poll_next_unpin(cx)).unwrap()
{
return Poll::Ready(());
}
})
.await
Expand Down
11 changes: 5 additions & 6 deletions muxers/mplex/tests/two_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ fn protocol_not_match() {
let mut transport = TcpTransport::default()
.and_then(move |c, e| upgrade::apply(c, mplex, e, upgrade::Version::V1))
.boxed();
match transport.dial(rx.await.unwrap()).unwrap().await {
Ok(_) => {
assert!(false, "Dialing should fail here as protocols do not match")
}
_ => {}
}

assert!(
transport.dial(rx.await.unwrap()).unwrap().await.is_err(),
"Dialing should fail here as protocols do not match"
);
});
}
1 change: 1 addition & 0 deletions protocols/autonat/examples/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(IdentifyEvent),
Expand Down
1 change: 1 addition & 0 deletions protocols/autonat/examples/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(IdentifyEvent),
Expand Down
40 changes: 16 additions & 24 deletions protocols/autonat/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,9 +264,8 @@ 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 {
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 protocols/autonat/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
1 change: 1 addition & 0 deletions protocols/dcutr/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
enum Event {
Ping(PingEvent),
Identify(IdentifyEvent),
Expand Down
3 changes: 0 additions & 3 deletions protocols/dcutr/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ fn connect() {
let mut dst = build_client();
let dst_peer_id = *dst.local_peer_id();
let dst_relayed_addr = relay_addr

.with(Protocol::P2p(relay_peer_id.into()))
.with(Protocol::P2pCircuit)
.with(Protocol::P2p(dst_peer_id.into()));
Expand Down Expand Up @@ -141,8 +140,6 @@ fn build_transport<StreamSink>(
where
StreamSink: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{


transport
.upgrade(Version::V1)
.authenticate(PlainText2Config { local_public_key })
Expand Down
Loading

0 comments on commit 345d986

Please sign in to comment.