.cargo: Run clippy on ALL the source files (#2949)

This commit is contained in:
Thomas Eizinger
2022-10-04 18:24:38 +11:00
committed by GitHub
parent e6da99e4f8
commit 1b793242e6
50 changed files with 5497 additions and 5657 deletions

View File

@ -598,7 +598,7 @@ mod tests {
let upgrade_timeout = Duration::from_secs(1);
let mut connection = Connection::new(
StreamMuxerBox::new(PendingStreamMuxer),
MockConnectionHandler::new(upgrade_timeout.clone()),
MockConnectionHandler::new(upgrade_timeout),
None,
2,
);

View File

@ -252,7 +252,7 @@ mod tests {
);
block_on(poll_fn(|cx| loop {
if let Poll::Pending = handler.poll(cx) {
if handler.poll(cx).is_pending() {
return Poll::Ready(());
}
}));

View File

@ -1724,7 +1724,7 @@ mod tests {
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
swarm1.listen_on(addr1.clone()).unwrap();
swarm1.listen_on(addr1).unwrap();
swarm2.listen_on(addr2.clone()).unwrap();
let swarm1_id = *swarm1.local_peer_id();
@ -1982,7 +1982,7 @@ mod tests {
let addr1: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
let addr2: Multiaddr = multiaddr::Protocol::Memory(rand::random::<u64>()).into();
swarm1.listen_on(addr1.clone()).unwrap();
swarm1.listen_on(addr1).unwrap();
swarm2.listen_on(addr2.clone()).unwrap();
let swarm1_id = *swarm1.local_peer_id();
@ -2090,7 +2090,7 @@ mod tests {
swarm
.dial(
DialOpts::peer_id(PeerId::random())
.addresses(listen_addresses.into())
.addresses(listen_addresses)
.build(),
)
.unwrap();
@ -2145,16 +2145,11 @@ mod tests {
.addresses(vec![addr.clone()])
.build(),
)
.ok()
.expect("Unexpected connection limit.");
}
match network
.dial(
DialOpts::peer_id(target)
.addresses(vec![addr.clone()])
.build(),
)
.dial(DialOpts::peer_id(target).addresses(vec![addr]).build())
.expect_err("Unexpected dialing success.")
{
DialError::ConnectionLimit(limit) => {
@ -2212,7 +2207,7 @@ mod tests {
// Spawn and block on the dialer.
async_std::task::block_on({
let mut n = 0;
let _ = network2.dial(listen_addr.clone()).unwrap();
network2.dial(listen_addr.clone()).unwrap();
let mut expected_closed = false;
let mut network_1_established = false;

View File

@ -388,7 +388,7 @@ mod tests {
// Add the first address.
addresses.add(first.addr.clone(), first.score);
assert!(addresses.iter().any(|a| &a.addr == &first.addr));
assert!(addresses.iter().any(|a| a.addr == first.addr));
// Add another address so often that the initial report of
// the first address may be purged and, since it was the
@ -397,7 +397,7 @@ mod tests {
addresses.add(other.addr.clone(), other.score);
}
let exists = addresses.iter().any(|a| &a.addr == &first.addr);
let exists = addresses.iter().any(|a| a.addr == first.addr);
match (first.score, other.score) {
// Only finite scores push out other finite scores.
@ -428,14 +428,14 @@ mod tests {
// Add the first address.
addresses.add(first.addr.clone(), first.score);
assert!(addresses.iter().any(|a| &a.addr == &first.addr));
assert!(addresses.iter().any(|a| a.addr == first.addr));
// Add another address so the first will address be purged,
// because its score is finite(0)
addresses.add(other.addr.clone(), other.score);
assert!(addresses.iter().any(|a| &a.addr == &other.addr));
assert!(!addresses.iter().any(|a| &a.addr == &first.addr));
assert!(addresses.iter().any(|a| a.addr == other.addr));
assert!(!addresses.iter().any(|a| a.addr == first.addr));
}
#[test]
@ -451,12 +451,14 @@ mod tests {
// Count the finitely scored addresses.
let num_finite = addresses
.iter()
.filter(|r| match r {
AddressRecord {
score: AddressScore::Finite(_),
..
} => true,
_ => false,
.filter(|r| {
matches!(
r,
AddressRecord {
score: AddressScore::Finite(_),
..
}
)
})
.count();
@ -476,13 +478,13 @@ mod tests {
// Add all address reports to the collection.
for r in records.iter() {
addresses.add(r.addr.clone(), r.score.clone());
addresses.add(r.addr.clone(), r.score);
}
// Check that each address in the registry has the expected score.
for r in &addresses.registry {
let expected_score = records.iter().fold(None::<AddressScore>, |sum, rec| {
if &rec.addr == &r.addr {
if rec.addr == r.addr {
sum.map_or(Some(rec.score), |s| Some(s + rec.score))
} else {
sum

View File

@ -232,7 +232,7 @@ where
}
fn addresses_of_peer(&mut self, p: &PeerId) -> Vec<Multiaddr> {
self.addresses_of_peer.push(p.clone());
self.addresses_of_peer.push(*p);
self.inner.addresses_of_peer(p)
}
@ -271,12 +271,8 @@ where
} else {
assert_eq!(other_established, 0)
}
self.inject_connection_established.push((
p.clone(),
c.clone(),
e.clone(),
other_established,
));
self.inject_connection_established
.push((*p, *c, e.clone(), other_established));
self.inner
.inject_connection_established(p, c, e, errors, other_established);
}
@ -349,7 +345,7 @@ where
"`inject_event` is never called for closed connections."
);
self.inject_event.push((p.clone(), c.clone(), e.clone()));
self.inject_event.push((p, c, e.clone()));
self.inner.inject_event(p, c, e);
}
@ -389,7 +385,7 @@ where
}
fn inject_listener_error(&mut self, l: ListenerId, e: &(dyn std::error::Error + 'static)) {
self.inject_listener_error.push(l.clone());
self.inject_listener_error.push(l);
self.inner.inject_listener_error(l, e);
}