File tree 2 files changed +23
-3
lines changed
2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,11 @@ impl From<libc::timespec> for Timespec {
149
149
}
150
150
}
151
151
152
- #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "watchos" ) ) ]
152
+ #[ cfg( any(
153
+ all( target_os = "macos" , not( target_arch = "aarch64" ) ) ,
154
+ target_os = "ios" ,
155
+ target_os = "watchos"
156
+ ) ) ]
153
157
mod inner {
154
158
use crate :: sync:: atomic:: { AtomicU64 , Ordering } ;
155
159
use crate :: sys:: cvt;
@@ -265,7 +269,11 @@ mod inner {
265
269
}
266
270
}
267
271
268
- #[ cfg( not( any( target_os = "macos" , target_os = "ios" , target_os = "watchos" ) ) ) ]
272
+ #[ cfg( not( any(
273
+ all( target_os = "macos" , not( target_arch = "aarch64" ) ) ,
274
+ target_os = "ios" ,
275
+ target_os = "watchos"
276
+ ) ) ) ]
269
277
mod inner {
270
278
use crate :: fmt;
271
279
use crate :: mem:: MaybeUninit ;
@@ -281,7 +289,11 @@ mod inner {
281
289
282
290
impl Instant {
283
291
pub fn now ( ) -> Instant {
284
- Instant { t : Timespec :: now ( libc:: CLOCK_MONOTONIC ) }
292
+ #[ cfg( target_os = "macos" ) ]
293
+ const clock_id: clock_t = libc:: CLOCK_UPTIME_RAW ;
294
+ #[ cfg( not( target_os = "macos" ) ) ]
295
+ const clock_id: clock_t = libc:: CLOCK_MONOTONIC ;
296
+ Instant { t : Timespec :: now ( clock_id) }
285
297
}
286
298
287
299
pub fn checked_sub_instant ( & self , other : & Instant ) -> Option < Duration > {
Original file line number Diff line number Diff line change @@ -88,6 +88,14 @@ fn instant_math_is_associative() {
88
88
// Changing the order of instant math shouldn't change the results,
89
89
// especially when the expression reduces to X + identity.
90
90
assert_eq ! ( ( now + offset) - now, ( now - now) + offset) ;
91
+
92
+ // On any platform, `Instant` should have the same resolution as `Duration` (e.g. 1 nanosecond)
93
+ // or better. Otherwise, math will be non-associative (see #91417).
94
+ let now = Instant :: now ( ) ;
95
+ let provided_offset = Duration :: from_nanos ( 1 ) ;
96
+ let later = now + provided_offset;
97
+ let measured_offset = later - now;
98
+ assert_eq ! ( measured_offset, provided_offset) ;
91
99
}
92
100
93
101
#[ test]
You can’t perform that action at this time.
0 commit comments