Skip to content

Implement Ord trait for Timespec - #4505

Closed
cpeterso wants to merge 6 commits into
rust-lang:incomingfrom
cpeterso:impl-timespec-ord
Closed

Implement Ord trait for Timespec#4505
cpeterso wants to merge 6 commits into
rust-lang:incomingfrom
cpeterso:impl-timespec-ord

Conversation

@cpeterso

Copy link
Copy Markdown
Contributor

Note that Timespec does not perform any range checking and this change does not add any!

This implementation of Ord assumes that pre-epoch Timespecs have negative sec and positivensec fields. Linux's and Darwin's struct timespec functions handle pre-epoch timestamps with this "two steps back, half step forward" representation, though I cannot find any documentation that actually puts this in writing. This means that (say) -1.2 seconds is represented by Timespec { sec: -2_i64, nsec: 800_000_000_i32 }, not something like Timespec { sec: -1_i64, nsec: -200_000_000_i32 } or Timespec { sec: -1_i64, nsec: 200_000_000_i32 }.

If we wish to codify this implementation detail, we could make Timespec nsec unsigned and add range checks asserting nsec <= 999_999_999_u32. btw, struct Tm also lacks range checking and uses signed integers for fields that can't be negative.

@cpetersocpeterso reopened this Jan 17, 2013
RalfJung added a commit to RalfJung/rust that referenced this pull request Aug 19, 2025
Use GH app for authenticating pull PRs
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
4505: Infer return type of loops with value breaks r=flodiebold a=ruabmbua
Creates a type variable to represent the return value of the loop.
Uses `coerce_merge_branch` on each break with the previous value, to determine the actual return value of the loop.
Resolves: rust-lang/rust-analyzer#4492 , rust-lang/rust-analyzer#4512
Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@cpeterso@pcwalton@jbclements@catamorphism