fix: clippy useless_conversion and useless_vec

Pull-Request: #4190.
This commit is contained in:
Benno
2023-07-16 05:31:37 +02:00
committed by GitHub
parent a3efb40892
commit 30024f38d4
7 changed files with 78 additions and 53 deletions

View File

@ -55,7 +55,7 @@ where
{
InboundUpgradeApply {
inner: InboundUpgradeApplyState::Init {
future: multistream_select::listener_select_proto(conn, up.protocol_info().into_iter()),
future: multistream_select::listener_select_proto(conn, up.protocol_info()),
upgrade: up,
},
}

View File

@ -354,9 +354,16 @@ mod tests {
.block_peer(*listener.local_peer_id());
let (
[SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }],
[SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }]
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
[SwarmEvent::ConnectionClosed {
peer_id: closed_dialer_peer,
..
}],
[SwarmEvent::ConnectionClosed {
peer_id: closed_listener_peer,
..
}],
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
else {
panic!("unexpected events")
};
assert_eq!(closed_dialer_peer, *listener.local_peer_id());
@ -417,9 +424,22 @@ mod tests {
.unwrap();
let (
[SwarmEvent::OutgoingConnectionError { error: DialError::Denied { cause: outgoing_cause }, .. }],
[_, SwarmEvent::IncomingConnectionError { error: ListenError::Denied { cause: incoming_cause }, .. }],
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
[SwarmEvent::OutgoingConnectionError {
error:
DialError::Denied {
cause: outgoing_cause,
},
..
}],
[_, SwarmEvent::IncomingConnectionError {
error:
ListenError::Denied {
cause: incoming_cause,
},
..
}],
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
else {
panic!("unexpected events")
};
assert!(outgoing_cause.downcast::<NotAllowed>().is_ok());
@ -447,9 +467,16 @@ mod tests {
.list
.disallow_peer(*listener.local_peer_id());
let (
[SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }],
[SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }]
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
[SwarmEvent::ConnectionClosed {
peer_id: closed_dialer_peer,
..
}],
[SwarmEvent::ConnectionClosed {
peer_id: closed_listener_peer,
..
}],
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
else {
panic!("unexpected events")
};
assert_eq!(closed_dialer_peer, *listener.local_peer_id());

View File

@ -411,7 +411,7 @@ mod tests {
assert!(len < (1 << 15));
let frame = (0..len).map(|n| (n & 0xff) as u8).collect::<Vec<_>>();
let mut data = vec![(len & 0x7f) as u8 | 0x80, (len >> 7) as u8];
data.extend(frame.clone().into_iter());
data.extend(frame.clone());
let mut framed = LengthDelimited::new(Cursor::new(data));
let recved = futures::executor::block_on(async move { framed.next().await }).unwrap();
assert_eq!(recved.unwrap(), frame);

View File

@ -47,10 +47,9 @@ fn select_proto_basic() {
let client = async_std::task::spawn(async move {
let protos = vec!["/proto3", "/proto2"];
let (proto, mut io) =
dialer_select_proto(client_connection, protos.into_iter(), version)
.await
.unwrap();
let (proto, mut io) = dialer_select_proto(client_connection, protos, version)
.await
.unwrap();
assert_eq!(proto, "/proto2");
io.write_all(b"ping").await.unwrap();
@ -99,25 +98,21 @@ fn negotiation_failed() {
}
});
let client =
async_std::task::spawn(async move {
let mut io =
match dialer_select_proto(client_connection, dial_protos.into_iter(), version)
.await
{
Err(NegotiationError::Failed) => return,
Ok((_, io)) => io,
Err(_) => panic!(),
};
// The dialer may write a payload that is even sent before it
// got confirmation of the last proposed protocol, when `V1Lazy`
// is used.
io.write_all(&dial_payload).await.unwrap();
match io.complete().await {
Err(NegotiationError::Failed) => {}
_ => panic!(),
}
});
let client = async_std::task::spawn(async move {
let mut io = match dialer_select_proto(client_connection, dial_protos, version).await {
Err(NegotiationError::Failed) => return,
Ok((_, io)) => io,
Err(_) => panic!(),
};
// The dialer may write a payload that is even sent before it
// got confirmation of the last proposed protocol, when `V1Lazy`
// is used.
io.write_all(&dial_payload).await.unwrap();
match io.complete().await {
Err(NegotiationError::Failed) => {}
_ => panic!(),
}
});
server.await;
client.await;
@ -185,10 +180,9 @@ async fn v1_lazy_do_not_wait_for_negotiation_on_poll_close() {
let client = async_std::task::spawn(async move {
// Single protocol to allow for lazy (or optimistic) protocol negotiation.
let protos = vec!["/proto1"];
let (proto, mut io) =
dialer_select_proto(client_connection, protos.into_iter(), Version::V1Lazy)
.await
.unwrap();
let (proto, mut io) = dialer_select_proto(client_connection, protos, Version::V1Lazy)
.await
.unwrap();
assert_eq!(proto, "/proto1");
// client can close the connection even though protocol negotiation is not yet done, i.e.

View File

@ -858,7 +858,7 @@ fn test_handle_received_subscriptions() {
// UNSUBSCRIBE - Remove topic from peer_topics for peer.
// - Remove peer from topic_peers.
let topics = vec!["topic1", "topic2", "topic3", "topic4"]
let topics = ["topic1", "topic2", "topic3", "topic4"]
.iter()
.map(|&t| String::from(t))
.collect();
@ -1280,7 +1280,7 @@ fn test_handle_graft_is_not_subscribed() {
#[test]
// tests multiple topics in a single graft message
fn test_handle_graft_multiple_topics() {
let topics: Vec<String> = vec!["topic1", "topic2", "topic3", "topic4"]
let topics: Vec<String> = ["topic1", "topic2", "topic3", "topic4"]
.iter()
.map(|&t| String::from(t))
.collect();

View File

@ -222,7 +222,7 @@ mod test {
let t1 = TopicHash::from_raw("t1");
let t2 = TopicHash::from_raw("t2");
let old = BTreeSet::from_iter(vec![t1.clone()].into_iter());
let old = BTreeSet::from_iter(vec![t1.clone()]);
let subscriptions = vec![
Subscription {
action: Unsubscribe,

View File

@ -40,9 +40,10 @@ fn webtransport_server_empty_certhashes() {
// Invalid case, because a MITM attacker may strip certificates of the server.
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
handshake_with_certhashes(vec![certhash1, certhash2], vec![]) else {
panic!("unexpected result");
};
handshake_with_certhashes(vec![certhash1, certhash2], vec![])
else {
panic!("unexpected result");
};
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
assert_eq!(received, HashSet::new());
@ -68,9 +69,10 @@ fn webtransport_server_uninit_certhashes() {
// Invalid case, because a MITM attacker may strip certificates of the server.
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
handshake_with_certhashes(vec![certhash1, certhash2], None) else {
panic!("unexpected result");
};
handshake_with_certhashes(vec![certhash1, certhash2], None)
else {
panic!("unexpected result");
};
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
assert_eq!(received, HashSet::new());
@ -81,9 +83,10 @@ fn webtransport_different_server_certhashes() {
let (certhash1, certhash2, certhash3) = certhashes();
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2]) else {
panic!("unexpected result");
};
handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2])
else {
panic!("unexpected result");
};
assert_eq!(expected, HashSet::from([certhash1, certhash3]));
assert_eq!(received, HashSet::from([certhash1, certhash2]));
@ -94,9 +97,10 @@ fn webtransport_superset_of_certhashes() {
let (certhash1, certhash2, _) = certhashes();
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1]) else {
panic!("unexpected result");
};
handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1])
else {
panic!("unexpected result");
};
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
assert_eq!(received, HashSet::from([certhash1]));