feat(ci): lint against usages of variables with underscore

Prefixing a variable with an underscore (`_`) in Rust indicates that it is not used. Through refactorings, it can sometimes happen that we do end up using such a variable. In this case, the underscore should be removed.

Clippy can help us with this.

Pull-Request: #3484.
This commit is contained in:
Thomas Eizinger
2023-02-24 19:34:59 +11:00
committed by GitHub
parent 6383e1e8bd
commit d80d92dc45
10 changed files with 90 additions and 65 deletions

View File

@ -1,3 +1,3 @@
[alias] [alias]
# Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped. # Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped.
custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -D warnings" custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -D warnings"

View File

@ -641,14 +641,14 @@ mod tests {
}; };
let dialer = async move { let dialer = async move {
let _chan = MemoryTransport::default() let chan = MemoryTransport::default()
.dial(listener_addr_cloned) .dial(listener_addr_cloned)
.unwrap() .unwrap()
.await .await
.unwrap(); .unwrap();
should_terminate.await.unwrap(); should_terminate.await.unwrap();
drop(_chan); drop(chan);
terminated.send(()).unwrap(); terminated.send(()).unwrap();
}; };

View File

@ -497,13 +497,13 @@ impl NetworkBehaviour for Behaviour {
fn handle_established_inbound_connection( fn handle_established_inbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
local_addr: &Multiaddr, local_addr: &Multiaddr,
remote_addr: &Multiaddr, remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> { ) -> Result<THandler<Self>, ConnectionDenied> {
self.inner.handle_established_inbound_connection( self.inner.handle_established_inbound_connection(
_connection_id, connection_id,
peer, peer,
local_addr, local_addr,
remote_addr, remote_addr,
@ -512,28 +512,28 @@ impl NetworkBehaviour for Behaviour {
fn handle_pending_outbound_connection( fn handle_pending_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
maybe_peer: Option<PeerId>, maybe_peer: Option<PeerId>,
_addresses: &[Multiaddr], addresses: &[Multiaddr],
_effective_role: Endpoint, effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> { ) -> Result<Vec<Multiaddr>, ConnectionDenied> {
self.inner.handle_pending_outbound_connection( self.inner.handle_pending_outbound_connection(
_connection_id, connection_id,
maybe_peer, maybe_peer,
_addresses, addresses,
_effective_role, effective_role,
) )
} }
fn handle_established_outbound_connection( fn handle_established_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
addr: &Multiaddr, addr: &Multiaddr,
role_override: Endpoint, role_override: Endpoint,
) -> Result<THandler<Self>, ConnectionDenied> { ) -> Result<THandler<Self>, ConnectionDenied> {
self.inner self.inner
.handle_established_outbound_connection(_connection_id, peer, addr, role_override) .handle_established_outbound_connection(connection_id, peer, addr, role_override)
} }
fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) { fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {

View File

@ -284,11 +284,11 @@ async fn test_throttle_global_max() {
..Default::default() ..Default::default()
})) }))
.await; .await;
let mut _handles = Vec::new(); let mut handles = Vec::new();
for _ in 0..2 { for _ in 0..2 {
let (_handle, rx) = oneshot::channel(); let (handle, rx) = oneshot::channel();
spawn_client(true, false, server_id, server_addr.clone(), rx).await; spawn_client(true, false, server_id, server_addr.clone(), rx).await;
_handles.push(_handle); handles.push(handle);
} }
let (first_probe_id, first_peer_id) = match next_event(&mut server).await { let (first_probe_id, first_peer_id) = match next_event(&mut server).await {

View File

@ -563,7 +563,7 @@ impl PeerScore {
} }
} }
pub fn validate_message(&mut self, _from: &PeerId, msg_id: &MessageId, topic_hash: &TopicHash) { pub fn validate_message(&mut self, from: &PeerId, msg_id: &MessageId, topic_hash: &TopicHash) {
// adds an empty record with the message id // adds an empty record with the message id
self.deliveries self.deliveries
.entry(msg_id.clone()) .entry(msg_id.clone())
@ -572,12 +572,12 @@ impl PeerScore {
if let Some(callback) = self.message_delivery_time_callback { if let Some(callback) = self.message_delivery_time_callback {
if self if self
.peer_stats .peer_stats
.get(_from) .get(from)
.and_then(|s| s.topics.get(topic_hash)) .and_then(|s| s.topics.get(topic_hash))
.map(|ts| ts.in_mesh()) .map(|ts| ts.in_mesh())
.unwrap_or(false) .unwrap_or(false)
{ {
callback(_from, topic_hash, 0.0); callback(from, topic_hash, 0.0);
} }
} }
} }

View File

@ -48,20 +48,20 @@ where
fn handle_established_inbound_connection( fn handle_established_inbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
local_addr: &Multiaddr, local_addr: &Multiaddr,
remote_addr: &Multiaddr, remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> { ) -> Result<THandler<Self>, ConnectionDenied> {
let handler = match self { let handler = match self {
Either::Left(inner) => Either::Left(inner.handle_established_inbound_connection( Either::Left(inner) => Either::Left(inner.handle_established_inbound_connection(
_connection_id, connection_id,
peer, peer,
local_addr, local_addr,
remote_addr, remote_addr,
)?), )?),
Either::Right(inner) => Either::Right(inner.handle_established_inbound_connection( Either::Right(inner) => Either::Right(inner.handle_established_inbound_connection(
_connection_id, connection_id,
peer, peer,
local_addr, local_addr,
remote_addr, remote_addr,
@ -73,23 +73,23 @@ where
fn handle_pending_outbound_connection( fn handle_pending_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
maybe_peer: Option<PeerId>, maybe_peer: Option<PeerId>,
_addresses: &[Multiaddr], addresses: &[Multiaddr],
_effective_role: Endpoint, effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> { ) -> Result<Vec<Multiaddr>, ConnectionDenied> {
let addresses = match self { let addresses = match self {
Either::Left(inner) => inner.handle_pending_outbound_connection( Either::Left(inner) => inner.handle_pending_outbound_connection(
_connection_id, connection_id,
maybe_peer, maybe_peer,
_addresses, addresses,
_effective_role, effective_role,
)?, )?,
Either::Right(inner) => inner.handle_pending_outbound_connection( Either::Right(inner) => inner.handle_pending_outbound_connection(
_connection_id, connection_id,
maybe_peer, maybe_peer,
_addresses, addresses,
_effective_role, effective_role,
)?, )?,
}; };
@ -98,20 +98,20 @@ where
fn handle_established_outbound_connection( fn handle_established_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
addr: &Multiaddr, addr: &Multiaddr,
role_override: Endpoint, role_override: Endpoint,
) -> Result<THandler<Self>, ConnectionDenied> { ) -> Result<THandler<Self>, ConnectionDenied> {
let handler = match self { let handler = match self {
Either::Left(inner) => Either::Left(inner.handle_established_outbound_connection( Either::Left(inner) => Either::Left(inner.handle_established_outbound_connection(
_connection_id, connection_id,
peer, peer,
addr, addr,
role_override, role_override,
)?), )?),
Either::Right(inner) => Either::Right(inner.handle_established_outbound_connection( Either::Right(inner) => Either::Right(inner.handle_established_outbound_connection(
_connection_id, connection_id,
peer, peer,
addr, addr,
role_override, role_override,

View File

@ -90,7 +90,7 @@ where
fn handle_established_inbound_connection( fn handle_established_inbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
local_addr: &Multiaddr, local_addr: &Multiaddr,
remote_addr: &Multiaddr, remote_addr: &Multiaddr,
@ -101,7 +101,7 @@ where
}; };
let handler = inner.handle_established_inbound_connection( let handler = inner.handle_established_inbound_connection(
_connection_id, connection_id,
peer, peer,
local_addr, local_addr,
remote_addr, remote_addr,
@ -114,10 +114,10 @@ where
fn handle_pending_outbound_connection( fn handle_pending_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
maybe_peer: Option<PeerId>, maybe_peer: Option<PeerId>,
_addresses: &[Multiaddr], addresses: &[Multiaddr],
_effective_role: Endpoint, effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> { ) -> Result<Vec<Multiaddr>, ConnectionDenied> {
let inner = match self.inner.as_mut() { let inner = match self.inner.as_mut() {
None => return Ok(vec![]), None => return Ok(vec![]),
@ -125,10 +125,10 @@ where
}; };
let addresses = inner.handle_pending_outbound_connection( let addresses = inner.handle_pending_outbound_connection(
_connection_id, connection_id,
maybe_peer, maybe_peer,
_addresses, addresses,
_effective_role, effective_role,
)?; )?;
Ok(addresses) Ok(addresses)
@ -136,7 +136,7 @@ where
fn handle_established_outbound_connection( fn handle_established_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
addr: &Multiaddr, addr: &Multiaddr,
role_override: Endpoint, role_override: Endpoint,
@ -147,7 +147,7 @@ where
}; };
let handler = inner.handle_established_outbound_connection( let handler = inner.handle_established_outbound_connection(
_connection_id, connection_id,
peer, peer,
addr, addr,
role_override, role_override,

View File

@ -92,7 +92,7 @@ impl ConnectionHandler for PendingConnectionHandler {
info: _info, info: _info,
}) => { }) => {
void::unreachable(protocol); void::unreachable(protocol);
#[allow(unreachable_code)] #[allow(unreachable_code, clippy::used_underscore_binding)]
{ {
void::unreachable(_info); void::unreachable(_info);
} }

View File

@ -420,19 +420,19 @@ where
fn handle_established_inbound_connection( fn handle_established_inbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
local_addr: &Multiaddr, local_addr: &Multiaddr,
remote_addr: &Multiaddr, remote_addr: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied> { ) -> Result<THandler<Self>, ConnectionDenied> {
self.handle_established_inbound_connection.push(( self.handle_established_inbound_connection.push((
peer, peer,
_connection_id, connection_id,
local_addr.clone(), local_addr.clone(),
remote_addr.clone(), remote_addr.clone(),
)); ));
self.inner.handle_established_inbound_connection( self.inner.handle_established_inbound_connection(
_connection_id, connection_id,
peer, peer,
local_addr, local_addr,
remote_addr, remote_addr,
@ -441,28 +441,28 @@ where
fn handle_pending_outbound_connection( fn handle_pending_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
maybe_peer: Option<PeerId>, maybe_peer: Option<PeerId>,
_addresses: &[Multiaddr], addresses: &[Multiaddr],
_effective_role: Endpoint, effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> { ) -> Result<Vec<Multiaddr>, ConnectionDenied> {
self.handle_pending_outbound_connection.push(( self.handle_pending_outbound_connection.push((
maybe_peer, maybe_peer,
_addresses.to_vec(), addresses.to_vec(),
_effective_role, effective_role,
_connection_id, connection_id,
)); ));
self.inner.handle_pending_outbound_connection( self.inner.handle_pending_outbound_connection(
_connection_id, connection_id,
maybe_peer, maybe_peer,
_addresses, addresses,
_effective_role, effective_role,
) )
} }
fn handle_established_outbound_connection( fn handle_established_outbound_connection(
&mut self, &mut self,
_connection_id: ConnectionId, connection_id: ConnectionId,
peer: PeerId, peer: PeerId,
addr: &Multiaddr, addr: &Multiaddr,
role_override: Endpoint, role_override: Endpoint,
@ -471,10 +471,10 @@ where
peer, peer,
addr.clone(), addr.clone(),
role_override, role_override,
_connection_id, connection_id,
)); ));
self.inner self.inner
.handle_established_outbound_connection(_connection_id, peer, addr, role_override) .handle_established_outbound_connection(connection_id, peer, addr, role_override)
} }
fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) { fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {

View File

@ -49,7 +49,12 @@ fn one_field() {
ping: ping::Behaviour, ping: ping::Behaviour,
} }
#[allow(dead_code, unreachable_code, clippy::diverging_sub_expression)] #[allow(
dead_code,
unreachable_code,
clippy::diverging_sub_expression,
clippy::used_underscore_binding
)]
fn foo() { fn foo() {
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!(); let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event { match _out_event {
@ -68,7 +73,12 @@ fn two_fields() {
identify: identify::Behaviour, identify: identify::Behaviour,
} }
#[allow(dead_code, unreachable_code, clippy::diverging_sub_expression)] #[allow(
dead_code,
unreachable_code,
clippy::diverging_sub_expression,
clippy::used_underscore_binding
)]
fn foo() { fn foo() {
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!(); let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event { match _out_event {
@ -91,7 +101,12 @@ fn three_fields() {
kad: libp2p_kad::Kademlia<libp2p_kad::record::store::MemoryStore>, kad: libp2p_kad::Kademlia<libp2p_kad::record::store::MemoryStore>,
} }
#[allow(dead_code, unreachable_code, clippy::diverging_sub_expression)] #[allow(
dead_code,
unreachable_code,
clippy::diverging_sub_expression,
clippy::used_underscore_binding
)]
fn foo() { fn foo() {
let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!(); let _out_event: <Foo as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event { match _out_event {
@ -219,7 +234,12 @@ fn nested_derives_with_import() {
foo: Foo, foo: Foo,
} }
#[allow(dead_code, unreachable_code, clippy::diverging_sub_expression)] #[allow(
dead_code,
unreachable_code,
clippy::diverging_sub_expression,
clippy::used_underscore_binding
)]
fn foo() { fn foo() {
let _out_event: <Bar as NetworkBehaviour>::OutEvent = unimplemented!(); let _out_event: <Bar as NetworkBehaviour>::OutEvent = unimplemented!();
match _out_event { match _out_event {
@ -259,7 +279,12 @@ fn custom_event_emit_event_through_poll() {
identify: identify::Behaviour, identify: identify::Behaviour,
} }
#[allow(dead_code, unreachable_code, clippy::diverging_sub_expression)] #[allow(
dead_code,
unreachable_code,
clippy::diverging_sub_expression,
clippy::used_underscore_binding
)]
async fn bar() { async fn bar() {
require_net_behaviour::<Foo>(); require_net_behaviour::<Foo>();