Skip to content

Duration.as_nanos() as u64 exceeds u64::MAX #137814

Closed
@marcusdesai

Description

@marcusdesai

I tried this code:

use std::time::Duration;

fn main() {
    let duration = Duration::from_secs(u64::MAX);
    assert_eq!(duration.as_nanos() as u64, u64::MAX)
}

I expected to see this happen: The assert to pass.

Instead, this happened: The assert fails with the following:

assertion `left == right` failed
  left: 18446744072709551616
 right: 18446744073709551615

Does not seem related to u128, as this passes:

assert_eq!(u128::MAX as u64, u64::MAX)

Meta

rustc --version --verbose:

rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-apple-darwin
release: 1.84.0
LLVM version: 19.1.5
Backtrace

I doub't the backtrace is much use, but just in case.

   0: rust_begin_unwind
             at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/panicking.rs:76:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: ansa::wait::tests::test
             at ./src/wait.rs:620:9
   5: ansa::wait::tests::test::{{closure}}
             at ./src/wait.rs:618:14
   6: core::ops::function::FnOnce::call_once
             at /Users/blank/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/ops/function.rs:250:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions