subsec_{milli,micro,nano}seconds
may have over-inclusive documented ranges
#669
Labels
A-docs
Area: documentation
Documentation of these functions promises that they will produce values in the ranges
-1_000..1_000
,-1_000_000..1_000_000
, and-1_000_000_000..1_000_000_000
, respectively, but I don't see how they could produce the lowest value in their stated bounds.In terms of code, I'll use
subsec_nanoseconds
as an example:time/time/src/duration.rs
Lines 912 to 923 in 7a6a800
self.nanoseconds
is aNanoseconds
, which is aRangedI32
- in particular, aRangedI32<{ -(Nanosecond::per(Second) as i32 - 1) }, { Nanosecond::per(Second) as i32 - 1 }>
.per
seems to be defined appropriately, so this gives usRangedI32<-999_999_999, 999_999_999>
. Given that aRangedI32<MIN, MAX>
promises to contain "[a]ni32
that is known to be in the rangeMIN..=MAX
", it's impossible for-1_000_000_000
to inhabitNanoseconds
, and so to be produced bysubsec_nanoseconds
.I believe the same logic can be extended to
subsec_microseconds
andsubsec_milliseconds
, since they defer tosubsec_nanoseconds
.The text was updated successfully, but these errors were encountered: