File tree 1 file changed +3
-2
lines changed
1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -311,7 +311,8 @@ impl Duration {
311
311
///
312
312
/// # Panics
313
313
///
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`
315
316
/// Use this function if you need to specify time greater than what can fit in u64
316
317
/// (around 584 years).
317
318
///
@@ -333,7 +334,7 @@ impl Duration {
333
334
panic ! ( "overflow in duration in Duration::from_nanos_u128" ) ;
334
335
}
335
336
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
337
338
let subsec_nanos = unsafe { Nanoseconds :: new_unchecked ( subsec_nanos) } ;
338
339
339
340
Duration { secs : secs as u64 , nanos : subsec_nanos }
You can’t perform that action at this time.
0 commit comments