Skip to content

Commit

Permalink
Rollup merge of rust-lang#94100 - lyinch:issue-91417-fix, r=yaahc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dylan-DPC committed Mar 18, 2022
2 parents 1bfe40d + 283ccc9 commit b888873
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.116"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core" }
libc = { version = "0.2.116", default-features = false, features = ['rustc-dep-of-std'] }
libc = { version = "0.2.119", default-features = false, features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "0.1.69" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand Down
14 changes: 10 additions & 4 deletions library/std/src/sys/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Hash for Timespec {
}
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(any(all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios"))]
mod inner {
use crate::fmt;
use crate::sync::atomic::{AtomicU64, Ordering};
Expand Down Expand Up @@ -263,7 +263,7 @@ mod inner {
}
}

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

impl Instant {
pub fn now() -> Instant {
Instant { t: now(libc::CLOCK_MONOTONIC) }
#[cfg(target_os = "macos")]
const clock_id: clock_t = libc::CLOCK_UPTIME_RAW;
#[cfg(not(target_os = "macos"))]
const clock_id: clock_t = libc::CLOCK_MONOTONIC;
Instant { t: now(clock_id) }
}

pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
Expand Down Expand Up @@ -343,10 +347,12 @@ mod inner {
}
}

#[cfg(not(any(target_os = "dragonfly", target_os = "espidf")))]
#[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "macos")))]
pub type clock_t = libc::c_int;
#[cfg(any(target_os = "dragonfly", target_os = "espidf"))]
pub type clock_t = libc::c_ulong;
#[cfg(target_os = "macos")]
pub type clock_t = libc::clockid_t;

fn now(clock: clock_t) -> Timespec {
let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } };
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/time/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ macro_rules! assert_almost_eq {
}};
}

#[test]
fn macos_resolution_regression() {
let t0 = Instant::now();
let t1 = t0 + Duration::from_nanos(50);
let d = t1 - t0;
assert_eq!(t0 + d, t1);
}

#[test]
fn instant_monotonic() {
let a = Instant::now();
Expand Down

0 comments on commit b888873

Please sign in to comment.