diff options
| author | bors <bors@rust-lang.org> | 2022-11-18 20:26:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-18 20:26:58 +0000 |
| commit | b833ad56f46a0bbe0e8729512812a161e7dae28a (patch) | |
| tree | 06ff2cca21b9852960818c4d0f79b3cac302a54c /library/std | |
| parent | 70fe5f08fffd16dc20506f7d140e47b074f77964 (diff) | |
| parent | 7e5e520c7daf193bc33f8dd12dfd9ec4ed1f261a (diff) | |
| download | rust-b833ad56f46a0bbe0e8729512812a161e7dae28a.tar.gz rust-b833ad56f46a0bbe0e8729512812a161e7dae28a.zip | |
Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1) - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting)) - #103405 (Detect incorrect chaining of if and if let conditions and recover) - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets) - #104006 (Add variant_name function to `LangItem`) - #104494 (Migrate GUI test to use functions) - #104516 (rustdoc: clean up sidebar width CSS) - #104550 (fix a typo) Failed merges: - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/sys/unix/time.rs | 25 | ||||
| -rw-r--r-- | library/std/src/time/tests.rs | 8 |
2 files changed, 24 insertions, 9 deletions
diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index cca9c676701..ffcc507d2a7 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -149,7 +149,11 @@ impl From<libc::timespec> for Timespec { } } -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos"))] +#[cfg(any( + all(target_os = "macos", any(not(target_arch = "aarch64"), miri)), + target_os = "ios", + target_os = "watchos" +))] mod inner { use crate::sync::atomic::{AtomicU64, Ordering}; use crate::sys::cvt; @@ -265,7 +269,11 @@ mod inner { } } -#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "watchos")))] +#[cfg(not(any( + all(target_os = "macos", any(not(target_arch = "aarch64"), miri)), + target_os = "ios", + target_os = "watchos" +)))] mod inner { use crate::fmt; use crate::mem::MaybeUninit; @@ -281,7 +289,11 @@ mod inner { impl Instant { pub fn now() -> Instant { - Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) } + #[cfg(target_os = "macos")] + const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW; + #[cfg(not(target_os = "macos"))] + const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC; + Instant { t: Timespec::now(clock_id) } } pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> { @@ -312,13 +324,8 @@ mod inner { } } - #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon")))] - pub type clock_t = libc::c_int; - #[cfg(any(target_os = "dragonfly", target_os = "espidf", target_os = "horizon"))] - pub type clock_t = libc::c_ulong; - impl Timespec { - pub fn now(clock: clock_t) -> Timespec { + pub fn now(clock: libc::clockid_t) -> Timespec { // Try to use 64-bit time in preparation for Y2038. #[cfg(all(target_os = "linux", target_env = "gnu", target_pointer_width = "32"))] { diff --git a/library/std/src/time/tests.rs b/library/std/src/time/tests.rs index 6229556c85f..2e64ae59aff 100644 --- a/library/std/src/time/tests.rs +++ b/library/std/src/time/tests.rs @@ -88,6 +88,14 @@ fn instant_math_is_associative() { // Changing the order of instant math shouldn't change the results, // especially when the expression reduces to X + identity. assert_eq!((now + offset) - now, (now - now) + offset); + + // On any platform, `Instant` should have the same resolution as `Duration` (e.g. 1 nanosecond) + // or better. Otherwise, math will be non-associative (see #91417). + let now = Instant::now(); + let provided_offset = Duration::from_nanos(1); + let later = now + provided_offset; + let measured_offset = later - now; + assert_eq!(measured_offset, provided_offset); } #[test] |
