From 65b0fc4d8b77b9c9b25b76538908443ce2c43c3f Mon Sep 17 00:00:00 2001 From: Christian Meusel Date: Mon, 21 Oct 2024 00:35:21 +0200 Subject: [PATCH] Use fallible conversion for tv_nsec in TimeSpec --- src/sys/time.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sys/time.rs b/src/sys/time.rs index 7e9875955e..4eb55f5bc7 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -391,6 +391,7 @@ impl TimeSpec { self.0.tv_nsec } + #[allow(clippy::unnecessary_fallible_conversions)] pub fn try_from_duration( duration: Duration, ) -> Result { @@ -399,7 +400,12 @@ impl TimeSpec { .as_secs() .try_into() .map_err(|_| TryFromDurationError)?; - ts.tv_nsec = duration.subsec_nanos().into(); + // There are targets with tv_nsec being i32. Use the fallible conversion for all targets as + // we are returning a Result due to the previous conversion anyway. + ts.tv_nsec = duration + .subsec_nanos() + .try_into() + .map_err(|_| TryFromDurationError)?; Ok(TimeSpec(ts)) }