Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
clippy: Deny and fix `fallible_impl_from`
Adrian Duke committed 3 months ago
commit 001aba0d292f1f5f5f334dff8e3d75bf709fe329
parent 02318f199c6f29a2eede1f282e1f9b99927d27ec
5 files changed +21 -18
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
@@ -415,7 +415,7 @@ impl From<CommentArgs> for CommentAction {
            (None, Some(react), None) => CommentAction::React {
                revision,
                comment: react,
-
                emoji: emoji.unwrap(),
+
                emoji: emoji.expect("emoji must be Some when react is Some"),
                undo,
            },
            (None, None, Some(redact)) => CommentAction::Redact {
modified crates/radicle-localtime/src/lib.rs
@@ -30,15 +30,22 @@ impl LocalTime {
    pub fn now() -> Self {
        static LAST: atomic::AtomicU64 = atomic::AtomicU64::new(0);

-
        let now = Self::from(SystemTime::now()).as_secs();
-
        let last = LAST.load(atomic::Ordering::SeqCst);
+
        let now = SystemTime::now()
+
            .duration_since(UNIX_EPOCH)
+
            .map(|duration| Self {
+
                millis: duration.as_millis(),
+
            })
+
            .expect("should run after 1970-01-01");
+

+
        let last_in_secs = LAST.load(atomic::Ordering::SeqCst);
+
        let now_in_secs = now.as_secs();

        // If the current time is in the past, return the last recorded time instead.
-
        if now < last {
-
            Self::from_secs(last)
+
        if now_in_secs < last_in_secs {
+
            Self::from_secs(last_in_secs)
        } else {
-
            LAST.store(now, atomic::Ordering::SeqCst);
-
            LocalTime::from_secs(now)
+
            LAST.store(now_in_secs, atomic::Ordering::SeqCst);
+
            now
        }
    }

@@ -94,15 +101,6 @@ 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();
-

-
        Self { millis }
-
    }
-
}
-

/// Subtract two local times. Yields a duration.
impl std::ops::Sub<LocalTime> for LocalTime {
    type Output = LocalDuration;
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
@@ -5,7 +5,7 @@ use std::collections::hash_map::Entry;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::sync::Arc;
-
use std::time::{Instant, SystemTime};
+
use std::time::Instant;
use std::{io, net, time};

use crossbeam_channel as chan;
@@ -13,6 +13,7 @@ use cyphernet::addr::{HostName, InetHost, NetAddr};
use cyphernet::encrypt::noise::{HandshakePattern, Keyset, NoiseState};
use cyphernet::proxy::socks5;
use cyphernet::{Digest, EcSk, Ecdh, Sha256};
+
use localtime::LocalTime;
use mio::net::TcpStream;
use radicle::node::device::Device;

@@ -510,7 +511,7 @@ where
            .sum();
        self.metrics.worker_queue_size = self.worker.len();

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

    fn timer_reacted(&mut self) {