rust-lang / rust-lang/rust

Checked arithmetic is wrong for Durations smaller than 100ns on Windows

Open
#149,995 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage O-windows T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

let system_time: SystemTime = ...;

// Add 1ns.
system_time.checked_add(Duration::new(0, 1)).unwrap();

I expected to see this happen: The unwrap to fail because SystemTime on Windows only has an accuracy of 100ns.

Instead, this happened: The addition "works" by returning some, although the value is unchanged from the original one, meaning an addition of a Duration < 100ns is equivalent of adding Duration::ZERO.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Rust's SystemTime::checked_add entry point and reproduce the example on Windows, comparing a 1ns duration with the platform's 100ns precision. Done means the sub-100ns addition no longer succeeds as a no-op, with the behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.