Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: fallible impl from
Adrian Duke committed 3 months ago
commit cd5cb0533b7f015b294898c35b42dc8dccac3994
parent 02318f199c6f29a2eede1f282e1f9b99927d27ec
5 files changed +17 -7
modified Cargo.toml
@@ -81,6 +81,7 @@ radicle-surf = "0.26.0"
[workspace.lints]
clippy.type_complexity = "allow"
clippy.enum_variant_names = "allow"
+
clippy.fallible_impl_from = "deny"

[profile.container]
inherits = "release"
modified crates/radicle-cli/src/commands/patch/args.rs
@@ -393,6 +393,9 @@ pub(super) enum CommentAction {
    },
}

+
// `emoji.unwrap()` is safe because an --emoji is required by --react and
+
// --react requires --emoji in Clap. See CommentArts::react and CommentArgs::emoji.
+
#[allow(clippy::fallible_impl_from)]
impl From<CommentArgs> for CommentAction {
    fn from(
        CommentArgs {
modified crates/radicle-localtime/src/lib.rs
@@ -3,7 +3,7 @@
//! Taken from <https://github.com/cloudhead/localtime>

use std::sync::atomic;
-
use std::time::{SystemTime, UNIX_EPOCH};
+
use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};

/// Local time.
///
@@ -30,7 +30,7 @@ impl LocalTime {
    pub fn now() -> Self {
        static LAST: atomic::AtomicU64 = atomic::AtomicU64::new(0);

-
        let now = Self::from(SystemTime::now()).as_secs();
+
        let now = Self::try_from(SystemTime::now()).unwrap().as_secs();
        let last = LAST.load(atomic::Ordering::SeqCst);

        // If the current time is in the past, return the last recorded time instead.
@@ -95,11 +95,13 @@ impl LocalTime {
}

/// Convert a `SystemTime` into a local time.
-
impl From<SystemTime> for LocalTime {
-
    fn from(system: SystemTime) -> Self {
-
        let millis = system.duration_since(UNIX_EPOCH).unwrap().as_millis();
+
impl TryFrom<SystemTime> for LocalTime {
+
    type Error = SystemTimeError;

-
        Self { millis }
+
    fn try_from(system: SystemTime) -> Result<Self, Self::Error> {
+
        system.duration_since(UNIX_EPOCH).map(|duration| Self {
+
            millis: duration.as_millis(),
+
        })
    }
}

modified crates/radicle-node/src/main.rs
@@ -51,6 +51,9 @@ enum Logger {
    Systemd,
}

+
// Required for Mac and potentially Windows as clippy complains because of the OS specific
+
// guard below.
+
#[allow(clippy::derivable_impls)]
impl Default for Logger {
    fn default() -> Self {
        #[cfg(all(feature = "systemd", target_os = "linux"))]
modified crates/radicle-node/src/wire.rs
@@ -510,7 +510,8 @@ where
            .sum();
        self.metrics.worker_queue_size = self.worker.len();

-
        self.service.tick(SystemTime::now().into(), &self.metrics);
+
        self.service
+
            .tick(SystemTime::now().try_into().unwrap(), &self.metrics);
    }

    fn timer_reacted(&mut self) {