Skip to content

Commit 65b0fc4

Browse files
committed
Use fallible conversion for tv_nsec in TimeSpec
1 parent d630718 commit 65b0fc4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sys/time.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ impl TimeSpec {
391391
self.0.tv_nsec
392392
}
393393

394+
#[allow(clippy::unnecessary_fallible_conversions)]
394395
pub fn try_from_duration(
395396
duration: Duration,
396397
) -> Result<Self, TryFromDurationError> {
@@ -399,7 +400,12 @@ impl TimeSpec {
399400
.as_secs()
400401
.try_into()
401402
.map_err(|_| TryFromDurationError)?;
402-
ts.tv_nsec = duration.subsec_nanos().into();
403+
// There are targets with tv_nsec being i32. Use the fallible conversion for all targets as
404+
// we are returning a Result due to the previous conversion anyway.
405+
ts.tv_nsec = duration
406+
.subsec_nanos()
407+
.try_into()
408+
.map_err(|_| TryFromDurationError)?;
403409
Ok(TimeSpec(ts))
404410
}
405411

0 commit comments

Comments
 (0)