Skip to content

Commit

Permalink
clippy: warn on unsused async fn (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored Oct 30, 2023
1 parent fa9fa83 commit 7068f33
Show file tree
Hide file tree
Showing 36 changed files with 138 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
rustflags = ["-Wmissing_debug_implementations"]
rustflags = []
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: dtolnay/rust-toolchain@stable
# Can be switched back once 1.75 lands
# https://github.com/rust-lang/cargo/issues/12115#issuecomment-1768170381
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy

Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ debug-assertions = false
opt-level = 3
panic = 'abort'
incremental = false


[workspace.lints.rust]
missing_debug_implementations = "warn"

[workspace.lints.clippy]
unused-async = "warn"
3 changes: 3 additions & 0 deletions iroh-bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/n0-computer/iroh"
# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.72"

[lints]
workspace = true

[dependencies]
anyhow = { version = "1", features = ["backtrace"] }
bao-tree = { version = "0.9.1", features = ["tokio_fsm"], default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion iroh-bytes/src/hashseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ pub struct HashSeqStream(HashSeq);

impl HashSeqStream {
/// Get the next hash in the sequence.
#[allow(clippy::should_implement_trait)]
#[allow(clippy::should_implement_trait, clippy::unused_async)]
pub async fn next(&mut self) -> io::Result<Option<Hash>> {
Ok(self.0.pop_front())
}

/// Skip a number of hashes in the sequence.
#[allow(clippy::unused_async)]
pub async fn skip(&mut self, n: u64) -> io::Result<()> {
let ok = self.0.drop_front(n as usize);
if !ok {
Expand Down
3 changes: 3 additions & 0 deletions iroh-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/n0-computer/iroh-sync"
# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.72"

[lints]
workspace = true

[dependencies]
# proto dependencies (required)
anyhow = { version = "1", features = ["backtrace"] }
Expand Down
2 changes: 1 addition & 1 deletion iroh-gossip/examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn main() -> anyhow::Result<()> {
println!("> trying to connect to {} peers...", peers.len());
// add the peer addrs from the ticket to our endpoint's addressbook so that they can be dialed
for peer in peers.into_iter() {
endpoint.add_peer_addr(peer).await?;
endpoint.add_peer_addr(peer)?;
}
};
gossip.join(topic, peer_ids).await?.await?;
Expand Down
10 changes: 5 additions & 5 deletions iroh-gossip/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Gossip {
///
/// Make sure to check the ALPN protocol yourself before passing the connection.
pub async fn handle_connection(&self, conn: quinn::Connection) -> anyhow::Result<()> {
let peer_id = get_peer_id(&conn).await?;
let peer_id = get_peer_id(&conn)?;
self.send(ToActor::ConnIncoming(peer_id, ConnOrigin::Accept, conn))
.await?;
Ok(())
Expand Down Expand Up @@ -371,7 +371,7 @@ impl Actor {
new_endpoints = self.on_endpoints_rx.recv() => {
match new_endpoints {
Some(endpoints) => {
let addr = self.endpoint.my_addr_with_endpoints(endpoints).await?;
let addr = self.endpoint.my_addr_with_endpoints(endpoints)?;
let peer_data = encode_peer_data(&addr.info)?;
self.handle_in_event(InEvent::UpdatePeerData(peer_data), Instant::now()).await?;
}
Expand Down Expand Up @@ -556,7 +556,7 @@ impl Actor {
peer_id: peer,
info,
};
if let Err(err) = self.endpoint.add_peer_addr(peer_addr).await {
if let Err(err) = self.endpoint.add_peer_addr(peer_addr) {
debug!(peer = ?peer, "add known failed: {err:?}");
}
}
Expand Down Expand Up @@ -733,8 +733,8 @@ mod test {
let topic: TopicId = blake3::hash(b"foobar").into();
// share info that pi1 is on the same derp_region
let addr1 = PeerAddr::new(pi1).with_derp_region(derp_region);
ep2.add_peer_addr(addr1.clone()).await.unwrap();
ep3.add_peer_addr(addr1).await.unwrap();
ep2.add_peer_addr(addr1.clone()).unwrap();
ep3.add_peer_addr(addr1).unwrap();

debug!("----- joining ----- ");
// join the topics and wait for the connection to succeed
Expand Down
3 changes: 3 additions & 0 deletions iroh-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/n0-computer/iroh"
# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.72"

[lints]
workspace = true

[dependencies]
prometheus-client = { version = "0.21.0", optional = true }
once_cell = "1.17.0"
Expand Down
3 changes: 3 additions & 0 deletions iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/n0-computer/iroh"
# Sadly this also needs to be updated in .github/workflows/ci.yml
rust-version = "1.72"

[lints]
workspace = true

[dependencies]
aead = { version = "0.5.2", features = ["bytes"] }
anyhow = { version = "1", features = ["backtrace"] }
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/derp/http/mesh_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl MeshClients {
}
}

pub(crate) async fn mesh(
pub(crate) fn mesh(
&mut self,
) -> anyhow::Result<Vec<tokio::sync::mpsc::Receiver<MeshClientEvent>>> {
let addrs = match &self.mesh_addrs {
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/derp/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Server {
let mut mesh_clients =
MeshClients::new(mesh_key, server_key.clone(), mesh_addrs, packet_fwd);

let recvs = mesh_clients.mesh().await?;
let recvs = mesh_clients.mesh()?;
self.mesh_clients = Some(mesh_clients);
Ok(recvs)
}
Expand Down Expand Up @@ -406,7 +406,7 @@ impl ServerState {
// servers will be down & unable to be reached
// so we do not wait for all meshing to complete
// back as successfull before running the server
let _ = mesh_clients.mesh().await?;
let _ = mesh_clients.mesh()?;
Some(mesh_clients)
} else {
None
Expand Down
22 changes: 11 additions & 11 deletions iroh-net/src/magic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,21 @@ impl MagicEndpoint {
/// Get the DERP region we are connected to with the lowest latency.
///
/// Returns `None` if we are not connected to any DERP region.
pub async fn my_derp(&self) -> Option<u16> {
self.msock.my_derp().await
pub fn my_derp(&self) -> Option<u16> {
self.msock.my_derp()
}

/// Get the [`PeerAddr`] for this endpoint.
pub async fn my_addr(&self) -> Result<PeerAddr> {
let addrs = self.local_endpoints().await?;
let derp = self.my_derp().await;
let derp = self.my_derp();
let addrs = addrs.into_iter().map(|x| x.addr).collect();
Ok(PeerAddr::from_parts(self.peer_id(), derp, addrs))
}

/// Get the [`PeerAddr`] for this endpoint, while providing the endpoints.
pub async fn my_addr_with_endpoints(&self, eps: Vec<config::Endpoint>) -> Result<PeerAddr> {
let derp = self.my_derp().await;
pub fn my_addr_with_endpoints(&self, eps: Vec<config::Endpoint>) -> Result<PeerAddr> {
let derp = self.my_derp();
let addrs = eps.into_iter().map(|x| x.addr).collect();
Ok(PeerAddr::from_parts(self.peer_id(), derp, addrs))
}
Expand Down Expand Up @@ -423,7 +423,7 @@ impl MagicEndpoint {
///
/// If no UDP addresses and no DERP region is provided, it will error.
pub async fn connect(&self, peer_addr: PeerAddr, alpn: &[u8]) -> Result<quinn::Connection> {
self.add_peer_addr(peer_addr.clone()).await?;
self.add_peer_addr(peer_addr.clone())?;

let PeerAddr { peer_id, info } = peer_addr;
let addr = self.msock.get_mapping_addr(&peer_id).await;
Expand All @@ -432,7 +432,7 @@ impl MagicEndpoint {
(true, None) => {
anyhow!("No UDP addresses or DERP region provided. Unable to dial peer {peer_id:?}")
}
(true, Some(region)) if !self.msock.has_derp_region(region).await => {
(true, Some(region)) if !self.msock.has_derp_region(region) => {
anyhow!("No UDP addresses provided and we do not have any DERP configuration for DERP region {region}. Unable to dial peer {peer_id:?}")
}
_ => anyhow!("Failed to retrieve the mapped address from the magic socket. Unable to dial peer {peer_id:?}")
Expand Down Expand Up @@ -478,7 +478,7 @@ impl MagicEndpoint {
/// If no UDP addresses are added, and `derp_region` is `None`, it will error.
/// If no UDP addresses are added, and the given `derp_region` cannot be dialed, it will error.
// TODO: Make sync
pub async fn add_peer_addr(&self, peer_addr: PeerAddr) -> Result<()> {
pub fn add_peer_addr(&self, peer_addr: PeerAddr) -> Result<()> {
self.msock.add_peer_addr(peer_addr);
Ok(())
}
Expand Down Expand Up @@ -515,7 +515,7 @@ pub async fn accept_conn(
) -> Result<(PublicKey, String, quinn::Connection)> {
let alpn = get_alpn(&mut conn).await?;
let conn = conn.await?;
let peer_id = get_peer_id(&conn).await?;
let peer_id = get_peer_id(&conn)?;
Ok((peer_id, alpn, conn))
}

Expand All @@ -532,7 +532,7 @@ pub async fn get_alpn(connecting: &mut quinn::Connecting) -> Result<String> {
}

/// Extract the [`PublicKey`] from the peer's TLS certificate.
pub async fn get_peer_id(connection: &quinn::Connection) -> Result<PublicKey> {
pub fn get_peer_id(connection: &quinn::Connection) -> Result<PublicKey> {
let data = connection.peer_identity();
match data {
None => anyhow::bail!("no peer certificate found"),
Expand Down Expand Up @@ -693,7 +693,7 @@ mod tests {
// information for a peer
let endpoint = new_endpoint(secret_key.clone(), path.clone()).await;
assert!(endpoint.connection_infos().await.unwrap().is_empty());
endpoint.add_peer_addr(peer_addr).await.unwrap();
endpoint.add_peer_addr(peer_addr).unwrap();

info!("closing endpoint");
// close the endpoint and restart it
Expand Down
Loading

0 comments on commit 7068f33

Please sign in to comment.