diff --git a/src/libstd/sys/cloudabi/time.rs b/src/libstd/sys/cloudabi/time.rs index 5e502dcb2ba50..b6496d65deaa4 100644 --- a/src/libstd/sys/cloudabi/time.rs +++ b/src/libstd/sys/cloudabi/time.rs @@ -25,7 +25,7 @@ impl Instant { } } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { true } diff --git a/src/libstd/sys/hermit/time.rs b/src/libstd/sys/hermit/time.rs index 8372189546d07..c19de4643302a 100644 --- a/src/libstd/sys/hermit/time.rs +++ b/src/libstd/sys/hermit/time.rs @@ -128,7 +128,7 @@ impl Instant { Instant { t: Timespec::zero() } } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { true } diff --git a/src/libstd/sys/sgx/time.rs b/src/libstd/sys/sgx/time.rs index 4659f7ba71fe0..2f43acd158ea8 100644 --- a/src/libstd/sys/sgx/time.rs +++ b/src/libstd/sys/sgx/time.rs @@ -26,7 +26,7 @@ impl Instant { Some(Instant(self.0.checked_sub(*other)?)) } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { false } diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index a9122defa5506..0cf0f4818ed60 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -158,7 +158,7 @@ mod inner { Instant { t: 0 } } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { true } @@ -308,11 +308,21 @@ mod inner { } } - pub fn actually_monotonic() -> bool { - (cfg!(target_os = "linux") && cfg!(target_arch = "x86_64")) || - (cfg!(target_os = "linux") && cfg!(target_arch = "x86")) || - cfg!(target_os = "fuchsia") || - false // last clause, used so `||` is always trailing above + pub const fn actually_monotonic() -> bool { + // note: duplicate attributes may be optimized when + // conditional expressions in constant functions hits stable. + #[cfg(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "linux", target_arch = "x86"), + all(target_os = "fuchsia"), + ))] + { true } + #[cfg(not(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "linux", target_arch = "x86"), + all(target_os = "fuchsia"), + )))] + { false } } pub fn checked_sub_instant(&self, other: &Instant) -> Option { diff --git a/src/libstd/sys/vxworks/time.rs b/src/libstd/sys/vxworks/time.rs index cb3a4241ea601..4089751ce1b3c 100644 --- a/src/libstd/sys/vxworks/time.rs +++ b/src/libstd/sys/vxworks/time.rs @@ -147,7 +147,7 @@ mod inner { } } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { true } diff --git a/src/libstd/sys/wasi/time.rs b/src/libstd/sys/wasi/time.rs index 4394a22f9c233..3d759ecd7cada 100644 --- a/src/libstd/sys/wasi/time.rs +++ b/src/libstd/sys/wasi/time.rs @@ -29,7 +29,7 @@ impl Instant { Instant(Duration::from_secs(0)) } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { true } diff --git a/src/libstd/sys/wasm/time.rs b/src/libstd/sys/wasm/time.rs index dd9ad3760b050..180f088b54f27 100644 --- a/src/libstd/sys/wasm/time.rs +++ b/src/libstd/sys/wasm/time.rs @@ -17,7 +17,7 @@ impl Instant { Instant(Duration::from_secs(0)) } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { false } diff --git a/src/libstd/sys/windows/time.rs b/src/libstd/sys/windows/time.rs index bd533c93d434c..4f540df3e6ed4 100644 --- a/src/libstd/sys/windows/time.rs +++ b/src/libstd/sys/windows/time.rs @@ -41,7 +41,7 @@ impl Instant { perf_counter::PerformanceCounterInstant::now().into() } - pub fn actually_monotonic() -> bool { + pub const fn actually_monotonic() -> bool { false }