Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit aa83235

Browse files
committed
Move duration division out
1 parent 9cf04b5 commit aa83235

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/tools/miri/src/clock.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ impl Instant {
3939
InstantKind::Virtual { nanoseconds },
4040
InstantKind::Virtual { nanoseconds: earlier },
4141
) => {
42+
let duration = nanoseconds.saturating_sub(earlier);
4243
// It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9).
43-
let seconds = u64::try_from(
44-
nanoseconds.saturating_sub(earlier).saturating_div(1_000_000_000),
45-
)
46-
.unwrap();
44+
let seconds = u64::try_from(duration.saturating_div(1_000_000_000)).unwrap();
4745
// It is impossible for nanosecond to overflow because u32::MAX > 1e9.
48-
let nanosecond = u32::try_from(nanoseconds.wrapping_rem(1_000_000_000)).unwrap();
46+
let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap();
4947
Duration::new(seconds, nanosecond)
5048
}
5149
_ => panic!("all `Instant` must be of the same kind"),

0 commit comments

Comments
 (0)