about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-06-18 15:20:47 -0700
committerGitHub <noreply@github.com>2020-06-18 15:20:47 -0700
commite1549786ff6105af4f3e9be30496c812b7ca71b3 (patch)
tree44b16f8b8c7fdc44aa149fb0598311953da05941
parente0b59b2c07adec376b7c57fb3d81726b6bc2822d (diff)
parent9e510085ecaedaee86b44410a4b3e4c85d97d6e0 (diff)
downloadrust-e1549786ff6105af4f3e9be30496c812b7ca71b3.tar.gz
rust-e1549786ff6105af4f3e9be30496c812b7ca71b3.zip
Rollup merge of #72836 - poliorcetics:std-time-os-specificities, r=shepmaster
Complete the std::time documentation to warn about the inconsistencies between OS

Fixes #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.
-rw-r--r--src/libstd/time.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/time.rs b/src/libstd/time.rs
index bc3bfde6d75..295ebcbb729 100644
--- a/src/libstd/time.rs
+++ b/src/libstd/time.rs
@@ -60,6 +60,21 @@ pub use core::time::Duration;
 /// }
 /// ```
 ///
+/// # OS-specific behaviors
+///
+/// An `Instant` is a wrapper around system-specific types and it may behave
+/// differently depending on the underlying operating system. For example,
+/// the following snippet is fine on Linux but panics on macOS:
+///
+/// ```no_run
+/// use std::time::{Instant, Duration};
+///
+/// let now = Instant::now();
+/// let max_nanoseconds = u64::MAX / 1_000_000_000;
+/// let duration = Duration::new(max_nanoseconds, 0);
+/// println!("{:?}", now + duration);
+/// ```
+///
 /// # Underlying System calls
 /// Currently, the following system calls are being used to get the current time using `now()`:
 ///