clippy: Deny and fix `fallible_impl_from`

Instead of changing `impl From<SystemTime> for LocalTime` to `TryFrom`,
the implementation was removed, as there are not many callsites, and
they are well served by `LocalTime::now`.

radicle-localtime: drop TryFrom SystemTime

radicle-node: switch SystemTime usage with LocalTime
This commit is contained in:
Adrian Duke 2026-01-13 14:27:41 +00:00 committed by Lorenz Leutgeb
parent 02318f199c
commit 001aba0d29
5 changed files with 21 additions and 18 deletions

View File

@ -81,6 +81,7 @@ radicle-surf = "0.26.0"
[workspace.lints] [workspace.lints]
clippy.type_complexity = "allow" clippy.type_complexity = "allow"
clippy.enum_variant_names = "allow" clippy.enum_variant_names = "allow"
clippy.fallible_impl_from = "deny"
[profile.container] [profile.container]
inherits = "release" inherits = "release"

View File

@ -415,7 +415,7 @@ impl From<CommentArgs> for CommentAction {
(None, Some(react), None) => CommentAction::React { (None, Some(react), None) => CommentAction::React {
revision, revision,
comment: react, comment: react,
emoji: emoji.unwrap(), emoji: emoji.expect("emoji must be Some when react is Some"),
undo, undo,
}, },
(None, None, Some(redact)) => CommentAction::Redact { (None, None, Some(redact)) => CommentAction::Redact {

View File

@ -30,15 +30,22 @@ impl LocalTime {
pub fn now() -> Self { pub fn now() -> Self {
static LAST: atomic::AtomicU64 = atomic::AtomicU64::new(0); static LAST: atomic::AtomicU64 = atomic::AtomicU64::new(0);
let now = Self::from(SystemTime::now()).as_secs(); let now = SystemTime::now()
let last = LAST.load(atomic::Ordering::SeqCst); .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 the current time is in the past, return the last recorded time instead.
if now < last { if now_in_secs < last_in_secs {
Self::from_secs(last) Self::from_secs(last_in_secs)
} else { } else {
LAST.store(now, atomic::Ordering::SeqCst); LAST.store(now_in_secs, atomic::Ordering::SeqCst);
LocalTime::from_secs(now) 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. /// Subtract two local times. Yields a duration.
impl std::ops::Sub<LocalTime> for LocalTime { impl std::ops::Sub<LocalTime> for LocalTime {
type Output = LocalDuration; type Output = LocalDuration;

View File

@ -51,6 +51,9 @@ enum Logger {
Systemd, 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 { impl Default for Logger {
fn default() -> Self { fn default() -> Self {
#[cfg(all(feature = "systemd", target_os = "linux"))] #[cfg(all(feature = "systemd", target_os = "linux"))]

View File

@ -5,7 +5,7 @@ use std::collections::hash_map::Entry;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Instant, SystemTime}; use std::time::Instant;
use std::{io, net, time}; use std::{io, net, time};
use crossbeam_channel as chan; use crossbeam_channel as chan;
@ -13,6 +13,7 @@ use cyphernet::addr::{HostName, InetHost, NetAddr};
use cyphernet::encrypt::noise::{HandshakePattern, Keyset, NoiseState}; use cyphernet::encrypt::noise::{HandshakePattern, Keyset, NoiseState};
use cyphernet::proxy::socks5; use cyphernet::proxy::socks5;
use cyphernet::{Digest, EcSk, Ecdh, Sha256}; use cyphernet::{Digest, EcSk, Ecdh, Sha256};
use localtime::LocalTime;
use mio::net::TcpStream; use mio::net::TcpStream;
use radicle::node::device::Device; use radicle::node::device::Device;
@ -510,7 +511,7 @@ where
.sum(); .sum();
self.metrics.worker_queue_size = self.worker.len(); 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) { fn timer_reacted(&mut self) {