rust/library/core/tests
Matthias Krüger d2644d9fe9
Rollup merge of #114238 - jhpratt:fix-duration-div, r=thomcc
Fix implementation of `Duration::checked_div`

I ran across this while running some sanity checks on `time`. Quickcheck immediately found a bug, and as I'd modified the code from `std` I knew there was a bug here as well.

tl;dr this code fails ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1189a3efcdfc192c27d6d87815359353))

```rust
use std::time::Duration;

fn main() {
    assert_eq!(
        Duration::new(1, 1).checked_div(7),
        Some(Duration::new(0, 142_857_143)),
    );
}
```

The existing code determines that 1/7 = 0 (seconds), 1/7 = 0 (nanoseconds), 1 billion / 7 = 142,857,142 (extra nanoseconds). The billion comes from multiplying the remainder of the seconds (1) by the number of nanoseconds in a second. However, **this wrongly ignores any remaining nanoseconds**. This PR takes that into consideration, adds a test, and also changes the roundabout way of calculating the remainder into directly computing it.

Note: This is _not_ a rounding error. This result divides evenly.

`@rustbot` label +A-time +C-bug +S-waiting-on-reviewer +T-libs
2023-08-28 08:13:57 +02:00
..
fmt Update format_args!() test to account for inlining. 2023-03-16 11:21:50 +01:00
hash fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
iter Add Iterator::map_windows 2023-08-11 07:26:51 +08:00
net Fix SocketAddrV6: Display tests 2023-06-14 15:21:15 -04:00
num Auto merge of #92048 - Urgau:num-midpoint, r=scottmcm 2023-05-14 19:33:02 +00:00
ops
panic
alloc.rs
any.rs core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
array.rs ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
ascii.rs
asserting.rs Spelling library/ 2023-04-26 02:10:22 -04:00
atomic.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
bool.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
cell.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
char.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
clone.rs Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
cmp.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
const_ptr.rs
convert.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
error.rs core/any: remove Provider trait 2023-08-13 13:07:53 -06:00
future.rs enable test_join test in Miri 2023-07-03 14:05:55 +02:00
intrinsics.rs
lazy.rs Rollup merge of #110419 - jsoref:spelling-library, r=jyn514 2023-04-26 18:51:41 +02:00
lib.rs Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieu 2023-08-14 18:18:03 +00:00
macros.rs
manually_drop.rs Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
mem.rs Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
nonzero.rs Implement Neg for signed non-zero integers. 2023-04-20 14:27:29 +09:00
ops.rs
option.rs fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
panic.rs
pattern.rs
pin_macro.rs
pin.rs
ptr.rs Extend unused_must_use to cover block exprs 2023-06-15 17:59:13 +08:00
result.rs
simd.rs
slice.rs Add more comprehensive tests for is_sorted and friends 2023-06-16 03:04:34 -04:00
str_lossy.rs
str.rs
task.rs
time.rs Fix implementation of Duration::checked_div 2023-07-30 04:00:02 -04:00
tuple.rs
unicode.rs
waker.rs