From 17234dbb3db8f4715fc0c96c0e5c5444a5980eb9 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 11 Apr 2021 21:37:46 -0700 Subject: [PATCH 1/3] Pretend Duration::MAX was part of duration_saturating_ops --- library/core/src/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 2219353b055ad..7db03367fd534 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -146,7 +146,7 @@ impl Duration { /// /// assert_eq!(Duration::MAX, Duration::new(u64::MAX, 1_000_000_000 - 1)); /// ``` - #[unstable(feature = "duration_constants", issue = "57391")] + #[stable(feature = "duration_saturating_ops", since = "1.53.0")] pub const MAX: Duration = Duration::new(u64::MAX, NANOS_PER_SEC - 1); /// Creates a new `Duration` from the specified number of whole seconds and From a80dbea918d6dd0516439f399a62512753276da5 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 19 Apr 2021 16:31:30 -0700 Subject: [PATCH 2/3] Clarify Duration::MAX depends on Instant Duration is used in std to represent a difference between two Instants. As such, it has to at least contain that span of time in it. However, Instant can vary by platform. Thus, we should explain the impl of Duration::MAX is sensitive to these vagaries of the platform. --- library/core/src/time.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 7db03367fd534..d7fa5f9bf0a75 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -136,16 +136,18 @@ impl Duration { /// The maximum duration. /// - /// It is roughly equal to a duration of 584,942,417,355 years. + /// May vary by platform. At least equal to the number of seconds + /// difference between the minimum and maximum [`std::time::Instant`]. + /// On many platforms this is roughly 584,942,417,355 years. /// /// # Examples /// /// ``` - /// #![feature(duration_constants)] /// use std::time::Duration; /// /// assert_eq!(Duration::MAX, Duration::new(u64::MAX, 1_000_000_000 - 1)); /// ``` + /// [`std::time::Instant`]: ../../std/time/struct.Instant.html #[stable(feature = "duration_saturating_ops", since = "1.53.0")] pub const MAX: Duration = Duration::new(u64::MAX, NANOS_PER_SEC - 1); From 8278380047c05539daf404adc17018de4570ddde Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 25 Apr 2021 10:28:23 -0700 Subject: [PATCH 3/3] Update to reflect feedback on the constraints --- library/core/src/time.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index d7fa5f9bf0a75..5af4f11bb7857 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -136,9 +136,10 @@ impl Duration { /// The maximum duration. /// - /// May vary by platform. At least equal to the number of seconds - /// difference between the minimum and maximum [`std::time::Instant`]. - /// On many platforms this is roughly 584,942,417,355 years. + /// May vary by platform as necessary. Must be able to contain the difference between + /// two instances of [`Instant`] or two instances of [`SystemTime`]. + /// This constraint gives it a value of about 584,942,417,355 years in practice, + /// which is currently used on all platforms. /// /// # Examples /// @@ -147,7 +148,8 @@ impl Duration { /// /// assert_eq!(Duration::MAX, Duration::new(u64::MAX, 1_000_000_000 - 1)); /// ``` - /// [`std::time::Instant`]: ../../std/time/struct.Instant.html + /// [`Instant`]: ../../std/time/struct.Instant.html + /// [`SystemTime`]: ../../std/time/struct.SystemTime.html #[stable(feature = "duration_saturating_ops", since = "1.53.0")] pub const MAX: Duration = Duration::new(u64::MAX, NANOS_PER_SEC - 1);