Skip to content

Commit b888873

Browse files
authored
Rollup merge of rust-lang#94100 - lyinch:issue-91417-fix, r=yaahc
Issue rust-lang#91417 fix This is a regression test and a fixes rust-lang#91417 It also bumps the libc version to 0.2.119 because it requires the constant introduced here: rust-lang/libc#2689
2 parents 1bfe40d + 283ccc9 commit b888873

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1965,9 +1965,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
19651965

19661966
[[package]]
19671967
name = "libc"
1968-
version = "0.2.116"
1968+
version = "0.2.119"
19691969
source = "registry+https://github.com/rust-lang/crates.io-index"
1970-
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
1970+
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
19711971
dependencies = [
19721972
"rustc-std-workspace-core",
19731973
]

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1515
panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
18-
libc = { version = "0.2.116", default-features = false, features = ['rustc-dep-of-std'] }
18+
libc = { version = "0.2.119", default-features = false, features = ['rustc-dep-of-std'] }
1919
compiler_builtins = { version = "0.1.69" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }

library/std/src/sys/unix/time.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Hash for Timespec {
114114
}
115115
}
116116

117-
#[cfg(any(target_os = "macos", target_os = "ios"))]
117+
#[cfg(any(all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios"))]
118118
mod inner {
119119
use crate::fmt;
120120
use crate::sync::atomic::{AtomicU64, Ordering};
@@ -263,7 +263,7 @@ mod inner {
263263
}
264264
}
265265

266-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
266+
#[cfg(not(any(all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios")))]
267267
mod inner {
268268
use crate::fmt;
269269
use crate::sys::cvt;
@@ -285,7 +285,11 @@ mod inner {
285285

286286
impl Instant {
287287
pub fn now() -> Instant {
288-
Instant { t: now(libc::CLOCK_MONOTONIC) }
288+
#[cfg(target_os = "macos")]
289+
const clock_id: clock_t = libc::CLOCK_UPTIME_RAW;
290+
#[cfg(not(target_os = "macos"))]
291+
const clock_id: clock_t = libc::CLOCK_MONOTONIC;
292+
Instant { t: now(clock_id) }
289293
}
290294

291295
pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
@@ -343,10 +347,12 @@ mod inner {
343347
}
344348
}
345349

346-
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf")))]
350+
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "macos")))]
347351
pub type clock_t = libc::c_int;
348352
#[cfg(any(target_os = "dragonfly", target_os = "espidf"))]
349353
pub type clock_t = libc::c_ulong;
354+
#[cfg(target_os = "macos")]
355+
pub type clock_t = libc::clockid_t;
350356

351357
fn now(clock: clock_t) -> Timespec {
352358
let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } };

library/std/src/time/tests.rs

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ macro_rules! assert_almost_eq {
1212
}};
1313
}
1414

15+
#[test]
16+
fn macos_resolution_regression() {
17+
let t0 = Instant::now();
18+
let t1 = t0 + Duration::from_nanos(50);
19+
let d = t1 - t0;
20+
assert_eq!(t0 + d, t1);
21+
}
22+
1523
#[test]
1624
fn instant_monotonic() {
1725
let a = Instant::now();

0 commit comments

Comments
 (0)