From f83c11674287d4f56c43daac74d7461abfc0ddde Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 21 Oct 2024 16:42:06 +0200 Subject: [PATCH] radicle: Fix clippy warnings around `unwrap` The policy should be that we don't use unwraps outside of test code, unless we have a good reason to. --- radicle/src/lib.rs | 1 + radicle/src/node.rs | 1 + radicle/src/node/address/store.rs | 1 + radicle/src/node/db.rs | 1 + radicle/src/node/events.rs | 8 ++++++++ radicle/src/node/notifications/store.rs | 1 + radicle/src/node/policy/store.rs | 1 + radicle/src/node/refs/store.rs | 1 + radicle/src/node/routing.rs | 1 + radicle/src/profile.rs | 1 + radicle/src/rad.rs | 2 +- radicle/src/serde_ext.rs | 1 + radicle/src/storage.rs | 2 +- radicle/src/storage/refs.rs | 1 + radicle/src/version.rs | 1 + 15 files changed, 22 insertions(+), 2 deletions(-) diff --git a/radicle/src/lib.rs b/radicle/src/lib.rs index 993cfed7..2cb90032 100644 --- a/radicle/src/lib.rs +++ b/radicle/src/lib.rs @@ -1,6 +1,7 @@ #![allow(clippy::match_like_matches_macro)] #![allow(clippy::too_many_arguments)] #![allow(clippy::iter_nth_zero)] +#![warn(clippy::unwrap_used)] pub extern crate radicle_crypto as crypto; diff --git a/radicle/src/node.rs b/radicle/src/node.rs index b8ee1964..387171a1 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -1356,6 +1356,7 @@ impl AliasStore for HashMap { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*; use crate::assert_matches; diff --git a/radicle/src/node/address/store.rs b/radicle/src/node/address/store.rs index c17dbcf6..6ae6e9f6 100644 --- a/radicle/src/node/address/store.rs +++ b/radicle/src/node/address/store.rs @@ -489,6 +489,7 @@ impl sql::BindableWithIndex for AddressType { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use std::net; diff --git a/radicle/src/node/db.rs b/radicle/src/node/db.rs index 2a01c687..19c8705c 100644 --- a/radicle/src/node/db.rs +++ b/radicle/src/node/db.rs @@ -214,6 +214,7 @@ pub fn migrate(db: &sql::Connection) -> Result { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*; diff --git a/radicle/src/node/events.rs b/radicle/src/node/events.rs index 199f80d8..dba73a92 100644 --- a/radicle/src/node/events.rs +++ b/radicle/src/node/events.rs @@ -154,6 +154,8 @@ impl Emitter { /// Emit event to subscribers and drop those who can't receive it. /// Nb. subscribers are also dropped if their channel is full. pub fn emit(&self, event: T) { + // SAFETY: We deliberately propagate panics from other threads holding the lock. + #[allow(clippy::unwrap_used)] self.subscribers .lock() .unwrap() @@ -163,6 +165,8 @@ impl Emitter { /// Subscribe to events stream. pub fn subscribe(&self) -> chan::Receiver { let (sender, receiver) = chan::bounded(MAX_PENDING_EVENTS); + // SAFETY: We deliberately propagate panics from other threads holding the lock. + #[allow(clippy::unwrap_used)] let mut subs = self.subscribers.lock().unwrap(); subs.push(sender); @@ -171,11 +175,15 @@ impl Emitter { /// Number of subscribers. pub fn subscriptions(&self) -> usize { + // SAFETY: We deliberately propagate panics from other threads holding the lock. + #[allow(clippy::unwrap_used)] self.subscribers.lock().unwrap().len() } /// Number of messages that have not yet been received. pub fn pending(&self) -> usize { + // SAFETY: We deliberately propagate panics from other threads holding the lock. + #[allow(clippy::unwrap_used)] self.subscribers .lock() .unwrap() diff --git a/radicle/src/node/notifications/store.rs b/radicle/src/node/notifications/store.rs index ac7c3750..614037a1 100644 --- a/radicle/src/node/notifications/store.rs +++ b/radicle/src/node/notifications/store.rs @@ -393,6 +393,7 @@ mod parse { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use radicle_git_ext::ref_format::{qualified, refname}; diff --git a/radicle/src/node/policy/store.rs b/radicle/src/node/policy/store.rs index 4ef9f78e..3f52535f 100644 --- a/radicle/src/node/policy/store.rs +++ b/radicle/src/node/policy/store.rs @@ -354,6 +354,7 @@ impl AliasStore for Store { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use crate::assert_matches; diff --git a/radicle/src/node/refs/store.rs b/radicle/src/node/refs/store.rs index fde561c6..56c67cf7 100644 --- a/radicle/src/node/refs/store.rs +++ b/radicle/src/node/refs/store.rs @@ -173,6 +173,7 @@ impl Store for Database { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*; use crate::git::qualified; diff --git a/radicle/src/node/routing.rs b/radicle/src/node/routing.rs index 9973d6a8..403e7c0f 100644 --- a/radicle/src/node/routing.rs +++ b/radicle/src/node/routing.rs @@ -259,6 +259,7 @@ impl Store for Database { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use localtime::LocalTime; diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index df16a769..ce08cb45 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -733,6 +733,7 @@ impl Home { #[cfg(test)] #[cfg(not(target_os = "macos"))] +#[allow(clippy::unwrap_used)] mod test { use super::*; use std::fs; diff --git a/radicle/src/rad.rs b/radicle/src/rad.rs index 7cea4a49..b3fb88bd 100644 --- a/radicle/src/rad.rs +++ b/radicle/src/rad.rs @@ -1,5 +1,4 @@ #![allow(clippy::let_unit_value)] -#![warn(clippy::unwrap_used)] use std::io; use std::path::Path; use std::str::FromStr; @@ -388,6 +387,7 @@ pub fn setup_patch_upstream<'a>( } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod tests { use std::collections::HashMap; diff --git a/radicle/src/serde_ext.rs b/radicle/src/serde_ext.rs index 8e785e53..9a32ddbb 100644 --- a/radicle/src/serde_ext.rs +++ b/radicle/src/serde_ext.rs @@ -121,6 +121,7 @@ where } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*; diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index d1ac42f8..3396f2a8 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -628,7 +628,7 @@ pub trait WriteRepository: ReadRepository + SignRepository { fn set_head(&self) -> Result; /// Set the repository 'rad/id' to the canonical commit, agreed by quorum. fn set_identity_head(&self) -> Result { - let head = self.canonical_identity_head().unwrap(); + let head = self.canonical_identity_head()?; self.set_identity_head_to(head)?; Ok(head) diff --git a/radicle/src/storage/refs.rs b/radicle/src/storage/refs.rs index 9d72c231..df52e17c 100644 --- a/radicle/src/storage/refs.rs +++ b/radicle/src/storage/refs.rs @@ -462,6 +462,7 @@ pub mod canonical { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod tests { use crypto::test::signer::MockSigner; use qcheck_macros::quickcheck; diff --git a/radicle/src/version.rs b/radicle/src/version.rs index 81534386..2d2eff51 100644 --- a/radicle/src/version.rs +++ b/radicle/src/version.rs @@ -33,6 +33,7 @@ impl<'a> Version<'a> { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*;