diff --git a/Cargo.toml b/Cargo.toml index cf07d16c..85057f3c 100644 --- a/Cargo.toml +++ b/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" diff --git a/crates/radicle-cli/src/commands/patch/args.rs b/crates/radicle-cli/src/commands/patch/args.rs index 1d0ac156..b6de2dcd 100644 --- a/crates/radicle-cli/src/commands/patch/args.rs +++ b/crates/radicle-cli/src/commands/patch/args.rs @@ -415,7 +415,7 @@ impl From 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 { diff --git a/crates/radicle-localtime/src/lib.rs b/crates/radicle-localtime/src/lib.rs index d6144576..0c1d3d05 100644 --- a/crates/radicle-localtime/src/lib.rs +++ b/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 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 for LocalTime { type Output = LocalDuration; diff --git a/crates/radicle-node/src/main.rs b/crates/radicle-node/src/main.rs index 9fcd4cc8..03f221e1 100644 --- a/crates/radicle-node/src/main.rs +++ b/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"))] diff --git a/crates/radicle-node/src/wire.rs b/crates/radicle-node/src/wire.rs index 58ac544a..5d351f93 100644 --- a/crates/radicle-node/src/wire.rs +++ b/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) {