From 0a227f33a80f02ce0182d52ff1224ace87ad2101 Mon Sep 17 00:00:00 2001 From: newpavlov Date: Wed, 17 Jul 2019 18:36:15 +0300 Subject: [PATCH 1/4] stabilize duration_float --- src/libcore/time.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 0f5f91f41a8cd..767ab539877ff 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -505,13 +505,12 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); /// assert_eq!(dur.as_secs_f64(), 2.7); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub const fn as_secs_f64(&self) -> f64 { (self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64) @@ -523,13 +522,12 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); /// assert_eq!(dur.as_secs_f32(), 2.7); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub const fn as_secs_f32(&self) -> f32 { (self.secs as f32) + (self.nanos as f32) / (NANOS_PER_SEC as f32) @@ -543,13 +541,12 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::from_secs_f64(2.7); /// assert_eq!(dur, Duration::new(2, 700_000_000)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn from_secs_f64(secs: f64) -> Duration { const MAX_NANOS_F64: f64 = @@ -579,13 +576,12 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::from_secs_f32(2.7); /// assert_eq!(dur, Duration::new(2, 700_000_000)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn from_secs_f32(secs: f32) -> Duration { const MAX_NANOS_F32: f32 = @@ -614,14 +610,13 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); /// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000)); /// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn mul_f64(self, rhs: f64) -> Duration { Duration::from_secs_f64(rhs * self.as_secs_f64()) @@ -634,7 +629,6 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); @@ -643,7 +637,7 @@ impl Duration { /// assert_eq!(dur.mul_f32(3.14), Duration::new(8, 478_000_640)); /// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847799, 969_120_256)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn mul_f32(self, rhs: f32) -> Duration { Duration::from_secs_f32(rhs * self.as_secs_f32()) @@ -656,7 +650,6 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); @@ -664,7 +657,7 @@ impl Duration { /// // note that truncation is used, not rounding /// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn div_f64(self, rhs: f64) -> Duration { Duration::from_secs_f64(self.as_secs_f64() / rhs) @@ -677,7 +670,6 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur = Duration::new(2, 700_000_000); @@ -687,7 +679,7 @@ impl Duration { /// // note that truncation is used, not rounding /// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_598)); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn div_f32(self, rhs: f32) -> Duration { Duration::from_secs_f32(self.as_secs_f32() / rhs) @@ -697,14 +689,13 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur1 = Duration::new(2, 700_000_000); /// let dur2 = Duration::new(5, 400_000_000); /// assert_eq!(dur1.div_duration_f64(dur2), 0.5); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn div_duration_f64(self, rhs: Duration) -> f64 { self.as_secs_f64() / rhs.as_secs_f64() @@ -714,14 +705,13 @@ impl Duration { /// /// # Examples /// ``` - /// #![feature(duration_float)] /// use std::time::Duration; /// /// let dur1 = Duration::new(2, 700_000_000); /// let dur2 = Duration::new(5, 400_000_000); /// assert_eq!(dur1.div_duration_f32(dur2), 0.5); /// ``` - #[unstable(feature = "duration_float", issue = "54361")] + #[stable(feature = "duration_float", since = "1.38.0")] #[inline] pub fn div_duration_f32(self, rhs: Duration) -> f32 { self.as_secs_f32() / rhs.as_secs_f32() From ad3632401c42a6dd8bd7c4d22590b1963e663430 Mon Sep 17 00:00:00 2001 From: newpavlov Date: Wed, 17 Jul 2019 18:58:33 +0300 Subject: [PATCH 2/4] unconstify methods --- src/libcore/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 767ab539877ff..9285dce8af8eb 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -512,7 +512,7 @@ impl Duration { /// ``` #[stable(feature = "duration_float", since = "1.38.0")] #[inline] - pub const fn as_secs_f64(&self) -> f64 { + pub fn as_secs_f64(&self) -> f64 { (self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64) } @@ -529,7 +529,7 @@ impl Duration { /// ``` #[stable(feature = "duration_float", since = "1.38.0")] #[inline] - pub const fn as_secs_f32(&self) -> f32 { + pub fn as_secs_f32(&self) -> f32 { (self.secs as f32) + (self.nanos as f32) / (NANOS_PER_SEC as f32) } From 55ee8fe852d93ce7ac87a5fa36d371cf0f0b195d Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Tue, 30 Jul 2019 15:00:17 +0000 Subject: [PATCH 3/4] mark div_duration methods as unstable, update tracking issue --- src/libcore/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 9285dce8af8eb..6a5ba0afa42a6 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -695,7 +695,7 @@ impl Duration { /// let dur2 = Duration::new(5, 400_000_000); /// assert_eq!(dur1.div_duration_f64(dur2), 0.5); /// ``` - #[stable(feature = "duration_float", since = "1.38.0")] + #[unstable(feature = "div_duration", issue = "63139")] #[inline] pub fn div_duration_f64(self, rhs: Duration) -> f64 { self.as_secs_f64() / rhs.as_secs_f64() @@ -711,7 +711,7 @@ impl Duration { /// let dur2 = Duration::new(5, 400_000_000); /// assert_eq!(dur1.div_duration_f32(dur2), 0.5); /// ``` - #[stable(feature = "duration_float", since = "1.38.0")] + #[unstable(feature = "div_duration", issue = "63139")] #[inline] pub fn div_duration_f32(self, rhs: Duration) -> f32 { self.as_secs_f32() / rhs.as_secs_f32() From 4281e6136df6886462e8da4e45877f6eeecd552a Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Tue, 30 Jul 2019 16:41:03 +0000 Subject: [PATCH 4/4] fix tests --- src/libcore/time.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 6a5ba0afa42a6..5a0e4388e0325 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -689,6 +689,7 @@ impl Duration { /// /// # Examples /// ``` + /// #![feature(div_duration)] /// use std::time::Duration; /// /// let dur1 = Duration::new(2, 700_000_000); @@ -705,6 +706,7 @@ impl Duration { /// /// # Examples /// ``` + /// #![feature(div_duration)] /// use std::time::Duration; /// /// let dur1 = Duration::new(2, 700_000_000);