diff options
| author | Ralf Jung <post@ralfj.de> | 2025-09-05 09:07:08 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-09-05 09:07:08 +0200 |
| commit | 5cadd4541c96edf0caaf1847b3c13b1ced4d5121 (patch) | |
| tree | aade0e8a90125e9f8aa7e61e4e0b9a63329e2ec3 | |
| parent | 18683c20aec00908d06255f9688cc1efb6eff10c (diff) | |
| download | rust-5cadd4541c96edf0caaf1847b3c13b1ced4d5121.tar.gz rust-5cadd4541c96edf0caaf1847b3c13b1ced4d5121.zip | |
make use of Duration::from_nanos_u128
| -rw-r--r-- | src/tools/miri/src/clock.rs | 9 | ||||
| -rw-r--r-- | src/tools/miri/src/lib.rs | 1 |
2 files changed, 2 insertions, 8 deletions
diff --git a/src/tools/miri/src/clock.rs b/src/tools/miri/src/clock.rs index 34465e9cac6..47608f873a4 100644 --- a/src/tools/miri/src/clock.rs +++ b/src/tools/miri/src/clock.rs @@ -46,14 +46,7 @@ impl Instant { InstantKind::Virtual { nanoseconds: earlier }, ) => { let duration = nanoseconds.saturating_sub(earlier); - // `Duration` does not provide a nice constructor from a `u128` of nanoseconds, - // so we have to implement this ourselves. - // It is possible for second to overflow because u64::MAX < (u128::MAX / 1e9). - // It will be saturated to u64::MAX seconds if the value after division exceeds u64::MAX. - let seconds = u64::try_from(duration / 1_000_000_000).unwrap_or(u64::MAX); - // It is impossible for nanosecond to overflow because u32::MAX > 1e9. - let nanosecond = u32::try_from(duration.wrapping_rem(1_000_000_000)).unwrap(); - Duration::new(seconds, nanosecond) + Duration::from_nanos_u128(duration) } _ => panic!("all `Instant` must be of the same kind"), } diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 0856411b8e8..a00d9525fab 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -18,6 +18,7 @@ #![feature(derive_coerce_pointee)] #![feature(arbitrary_self_types)] #![feature(iter_advance_by)] +#![feature(duration_from_nanos_u128)] // Configure clippy and other lints #