Skip to content

Commit d2e35d8

Browse files
authored
Update time.rs
keeping seconds as u64 removing the use of non const function within const function
1 parent 860045c commit d2e35d8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/core/src/time.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ impl Duration {
310310

311311
/// Creates a new Duration from the specified number of nanoseconds.
312312
///
313+
/// # Panics
314+
///
315+
/// Panics if the given number of weeks overflows the `Duration` size.
313316
/// Use this function if you need to specify time greater than what can fit in u64
314317
/// (around 584 years).
315318
///
@@ -324,7 +327,7 @@ impl Duration {
324327
#[unstable(feature = "duration_from_nanos_u128", issue = "139201")]
325328
pub const fn from_nanos_u128(nanos: u128) -> Duration {
326329
const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128;
327-
let secs = u64::try_from(nanos / NANOS_PER_SEC).unwrap_or(u64::MAX);
330+
let secs : u64 = (nanos/ NANOS_PER_SEC) as u64 ;
328331
let subsec_nanos = (nanos % NANOS_PER_SEC) as u32;
329332
// SAFETY: x % 1_000_000_000 < 1_000_000_000
330333
let subsec_nanos = unsafe { Nanoseconds::new_unchecked(subsec_nanos) };

0 commit comments

Comments
 (0)