Skip to content

Commit 75d09d3

Browse files
authored
Rollup merge of rust-lang#72836 - poliorcetics:std-time-os-specificities, r=shepmaster
Complete the std::time documentation to warn about the inconsistencies between OS Fix for rust-lang#48980. I put the new documentation in `src/libstd/time.rs` at the module-level because it affects all types, even the one that are not directly system dependents if they are used with affected types, but there may be a better place for it.
2 parents 542474b + 9e51008 commit 75d09d3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/time.rs

+15
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ pub use core::time::Duration;
6060
/// }
6161
/// ```
6262
///
63+
/// # OS-specific behaviors
64+
///
65+
/// An `Instant` is a wrapper around system-specific types and it may behave
66+
/// differently depending on the underlying operating system. For example,
67+
/// the following snippet is fine on Linux but panics on macOS:
68+
///
69+
/// ```no_run
70+
/// use std::time::{Instant, Duration};
71+
///
72+
/// let now = Instant::now();
73+
/// let max_nanoseconds = u64::MAX / 1_000_000_000;
74+
/// let duration = Duration::new(max_nanoseconds, 0);
75+
/// println!("{:?}", now + duration);
76+
/// ```
77+
///
6378
/// # Underlying System calls
6479
/// Currently, the following system calls are being used to get the current time using `now()`:
6580
///

0 commit comments

Comments
 (0)