Skip to content

Commit 860045c

Browse files
making sure seconds are in u64
Co-authored-by: Madhav Madhusoodanan <[email protected]>
1 parent 9bfe135 commit 860045c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl Duration {
324324
#[unstable(feature = "duration_from_nanos_u128", issue = "139201")]
325325
pub const fn from_nanos_u128(nanos: u128) -> Duration {
326326
const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128;
327-
let secs = nanos / NANOS_PER_SEC;
327+
let secs = u64::try_from(nanos / NANOS_PER_SEC).unwrap_or(u64::MAX);
328328
let subsec_nanos = (nanos % NANOS_PER_SEC) as u32;
329329
// SAFETY: x % 1_000_000_000 < 1_000_000_000
330330
let subsec_nanos = unsafe { Nanoseconds::new_unchecked(subsec_nanos) };

0 commit comments

Comments
 (0)