@@ -133,9 +133,12 @@ pub use core::time::FromFloatSecsError;
133
133
/// if available, which is the case for all [tier 1] platforms.
134
134
/// In practice such guarantees are – under rare circumstances – broken by hardware, virtualization
135
135
/// or operating system bugs. To work around these bugs and platforms not offering monotonic clocks
136
- /// [`duration_since`], [`elapsed`] and [`sub`] saturate to zero. [`checked_duration_since`] can
137
- /// be used to detect and handle situations where monotonicity is violated, or `Instant`s are
138
- /// subtracted in the wrong order.
136
+ /// [`duration_since`], [`elapsed`] and [`sub`] saturate to zero. In older rust versions this
137
+ /// lead to a panic instead. [`checked_duration_since`] can be used to detect and handle situations
138
+ /// where monotonicity is violated, or `Instant`s are subtracted in the wrong order.
139
+ ///
140
+ /// This workaround obscures programming errors where earlier and later instants are accidentally
141
+ /// swapped. For this reason future rust versions may reintroduce panics.
139
142
///
140
143
/// [tier 1]: https://doc.rust-lang.org/rustc/platform-support.html
141
144
/// [`duration_since`]: Instant::duration_since
@@ -271,6 +274,13 @@ impl Instant {
271
274
/// Returns the amount of time elapsed from another instant to this one,
272
275
/// or zero duration if that instant is later than this one.
273
276
///
277
+ /// # Panics
278
+ ///
279
+ /// Previous rust versions panicked when `earlier` was later than `self`. Currently this
280
+ /// method saturates. Future versions may reintroduce the panic in some circumstances.
281
+ /// See [Monotonicity].
282
+ ///
283
+ /// [Monotonicity]: Instant#monotonicity
274
284
///
275
285
/// # Examples
276
286
///
@@ -339,6 +349,14 @@ impl Instant {
339
349
340
350
/// Returns the amount of time elapsed since this instant was created.
341
351
///
352
+ /// # Panics
353
+ ///
354
+ /// Previous rust versions panicked when self was earlier than the current time. Currently this
355
+ /// method returns a Duration of zero in that case. Future versions may reintroduce the panic.
356
+ /// See [Monotonicity].
357
+ ///
358
+ /// [Monotonicity]: Instant#monotonicity
359
+ ///
342
360
/// # Examples
343
361
///
344
362
/// ```no_run
@@ -413,6 +431,16 @@ impl SubAssign<Duration> for Instant {
413
431
impl Sub < Instant > for Instant {
414
432
type Output = Duration ;
415
433
434
+ /// Returns the amount of time elapsed from another instant to this one,
435
+ /// or zero duration if that instant is later than this one.
436
+ ///
437
+ /// # Panics
438
+ ///
439
+ /// Previous rust versions panicked when `other` was later than `self`. Currently this
440
+ /// method saturates. Future versions may reintroduce the panic in some circumstances.
441
+ /// See [Monotonicity].
442
+ ///
443
+ /// [Monotonicity]: Instant#monotonicity
416
444
fn sub ( self , other : Instant ) -> Duration {
417
445
self . duration_since ( other)
418
446
}
0 commit comments