@@ -103,6 +103,28 @@ pub use core::time::Duration;
103
103
/// > structure cannot represent the new point in time.
104
104
///
105
105
/// [`add`]: Instant::add
106
+ ///
107
+ /// ## Reliability
108
+ ///
109
+ /// On platforms where the underlying system call's API contract guarantees monotonicity
110
+ /// Instant may rely on that property. Otherwise it will add its own synchronization
111
+ /// to ensure monotonicity. Sometimes operating system guarantees are broken by hardware
112
+ /// or virtualization bugs. This can manifest in Duration between an older and newer Instant
113
+ /// appearing to be negative which results in a panic.
114
+ ///
115
+ /// On windows and some unix systems you can override rust's choice to add
116
+ /// its own synchronization or rely on the operating system by setting the environment variable
117
+ /// `RUST_CLOCK_ASSUME_MONOTONIC` to `1` (trust the system-provided time) or `0`
118
+ /// (apply additional synchronization). The value of the variable is only read
119
+ /// the first time an Instant is created. Altering it later will have no effect.
120
+ ///
121
+ /// > Note: The environment variable is experimental and meant to diagnose bugs.
122
+ /// > It is not part of the normal Rust stability guarantees.
123
+ ///
124
+ /// If you encounter a case where additional synchronization is necessary please
125
+ /// [file an issue]
126
+ ///
127
+ /// [file an issue]: https://github.com/rust-lang/rust/issues
106
128
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
107
129
#[ stable( feature = "time2" , since = "1.8.0" ) ]
108
130
pub struct Instant ( time:: Instant ) ;
@@ -327,7 +349,9 @@ impl Instant {
327
349
///
328
350
/// This function may panic if the current time is earlier than this
329
351
/// instant, which is something that can happen if an `Instant` is
330
- /// produced synthetically.
352
+ /// produced synthetically or due to [hardware bugs]
353
+ ///
354
+ /// [hardware bugs]: Instant#reliability
331
355
///
332
356
/// # Examples
333
357
///
0 commit comments