diff options
| author | tiif <pekyuan@gmail.com> | 2024-06-08 01:21:56 +0800 |
|---|---|---|
| committer | tiif <pekyuan@gmail.com> | 2024-06-09 18:00:58 +0800 |
| commit | aa8323585cf3b8846b4dd83f48404a26f7df63c9 (patch) | |
| tree | bd11971f63f2e5f9ae30e929ec6a1d70adb8aeef | |
| parent | 9cf04b5a22e20fd0a537196a610b0e2b85b8d485 (diff) | |
| download | rust-aa8323585cf3b8846b4dd83f48404a26f7df63c9.tar.gz rust-aa8323585cf3b8846b4dd83f48404a26f7df63c9.zip | |
Move duration division out
| -rw-r--r-- | src/tools/miri/src/clock.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index 942593530c3..b8d0c847069 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -39,13 +39,11 @@ impl Instant { InstantKind::Virtual { nanoseconds }, InstantKind::Virtual { nanoseconds: earlier }, ) => { + let duration = nanoseconds.saturating_sub(earlier); // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). - let seconds = u64::try_from( - nanoseconds.saturating_sub(earlier).saturating_div(1_000_000_000), - ) - .unwrap(); + let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap(); // It is impossible for nanosecond to overflow because u32::MAX > 1e9. - let nanosecond = u32::try_from(nanoseconds.wrapping_rem(1_000_000_000)).unwrap(); + let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap(); Duration::new(seconds, nanosecond) } _ => panic!("all `Instant` must be of the same kind"), |
