Skip to content

Commit 200c2d5

Browse files
Add comment on largest input and explain safety assumption
1 parent ea367d9 commit 200c2d5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/core/src/time.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ impl Duration {
311311
///
312312
/// # Panics
313313
///
314-
/// Panics if the given number of weeks overflows the `Duration` size.
314+
/// Panics if the given number of nanoseconds is greater than what Duration can handle,
315+
/// which is `(u64::MAX * NANOS_PER_SEC) + NANOS_PER_SEC - 1`
315316
/// Use this function if you need to specify time greater than what can fit in u64
316317
/// (around 584 years).
317318
///
@@ -333,7 +334,7 @@ impl Duration {
333334
panic!("overflow in duration in Duration::from_nanos_u128");
334335
}
335336
let subsec_nanos = (nanos % NANOS_PER_SEC) as u32;
336-
// SAFETY: x % 1_000_000_000 < 1_000_000_000
337+
// SAFETY: x % 1_000_000_000 < 1_000_000_000 also, subsec_nanos >= 0 since u128 >=0 and u32 >=0
337338
let subsec_nanos = unsafe { Nanoseconds::new_unchecked(subsec_nanos) };
338339

339340
Duration { secs: secs as u64, nanos: subsec_nanos }

0 commit comments

Comments
 (0)