From 06af3a63a597a40604976666dea19a503557855a Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Fri, 27 May 2022 00:22:56 +0000 Subject: [PATCH] add debug asserts --- library/core/src/time.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 6d098acb5ea..46fab01b1bf 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -1290,8 +1290,10 @@ macro_rules! try_from_secs { // note that neither `f32`, nor `f64` can represent // 0.999_999_999_5 exactly, so the nanos part - // never will be equal to 10^9. - (0, nanos + add_ns as u32) + // never will be equal to NANOS_PER_SEC + let nanos = nanos + add_ns as u32; + debug_assert!(nanos < NANOS_PER_SEC); + (0, nanos) } else if exp < $mant_bits { let secs = u64::from(mant >> ($mant_bits - exp)); let t = <$double_ty>::from((mant << exp) & MANT_MASK); @@ -1308,8 +1310,10 @@ macro_rules! try_from_secs { let add_ns = !(rem_msb || (is_even && is_tie)); // neither `f32`, nor `f64` can represent x.999_999_999_5 exactly, - // so the nanos part never will be equal to 10^9 - (secs, nanos + add_ns as u32) + // so the nanos part never will be equal to NANOS_PER_SEC + let nanos = nanos + add_ns as u32; + debug_assert!(nanos < NANOS_PER_SEC); + (secs, nanos) } else if exp < 64 { // the input has no fractional part let secs = u64::from(mant) << (exp - $mant_bits);