Skip to content

windows/time: avoid being too close to 0#156177

Open
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:windows-time-epoch
Open

windows/time: avoid being too close to 0#156177
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:windows-time-epoch

Conversation

@RalfJung
Copy link
Copy Markdown
Member

@RalfJung RalfJung commented May 5, 2026

Fixes #156142 (but only for Windows -- should we still track it for non-tier-1-platforms?)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 5, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@RalfJung RalfJung force-pushed the windows-time-epoch branch from 99d0aef to a07a3b1 Compare May 5, 2026 06:44
// We can add an arbitrary offset to shift the epoch of this clock. We do that to avoid
// being too close to 0 which would lead to underflow when computing times in the past. Also
// see <https://github.com/rust-lang/rust/issues/156142>.
let instant_nsec = instant_nsec + (u64::MAX / 4);
Copy link
Copy Markdown
Contributor

@tbu- tbu- May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer to use a signed type for storing the nanoseconds, otherwise we have this useless addition on every Instant::now.

Using a signed type would make this essentially free.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Duration so using anything singed would be a major refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] computing an Instant from before program startup might panic

4 participants