Skip to content

Commit 658c148

Browse files
Rollup merge of #89542 - jhpratt:stabilize-duration-const-fns, r=oli-obk
Partially stabilize `duration_consts_2` Methods that were only blocked on `const_panic` have been stabilized. The remaining methods of `duration_consts_2` are all related to floats, and as such have been placed behind the `duration_consts_float` feature gate.
2 parents 8a48b37 + 88b0d7c commit 658c148

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
#![feature(const_type_id)]
139139
#![feature(const_type_name)]
140140
#![feature(const_default_impls)]
141-
#![feature(duration_consts_2)]
141+
#![feature(duration_consts_float)]
142142
#![feature(ptr_metadata)]
143143
#![feature(slice_ptr_get)]
144144
#![feature(str_internals)]

library/core/src/time.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ impl Duration {
180180
/// ```
181181
#[stable(feature = "duration", since = "1.3.0")]
182182
#[inline]
183-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
184183
#[must_use]
184+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
185+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
185186
pub const fn new(secs: u64, nanos: u32) -> Duration {
186187
let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) {
187188
Some(secs) => secs,
@@ -480,7 +481,8 @@ impl Duration {
480481
#[must_use = "this returns the result of the operation, \
481482
without modifying the original"]
482483
#[inline]
483-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
484+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
485+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
484486
pub const fn checked_add(self, rhs: Duration) -> Option<Duration> {
485487
if let Some(mut secs) = self.secs.checked_add(rhs.secs) {
486488
let mut nanos = self.nanos + rhs.nanos;
@@ -515,7 +517,7 @@ impl Duration {
515517
#[must_use = "this returns the result of the operation, \
516518
without modifying the original"]
517519
#[inline]
518-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
520+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
519521
pub const fn saturating_add(self, rhs: Duration) -> Duration {
520522
match self.checked_add(rhs) {
521523
Some(res) => res,
@@ -540,7 +542,8 @@ impl Duration {
540542
#[must_use = "this returns the result of the operation, \
541543
without modifying the original"]
542544
#[inline]
543-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
545+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
546+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
544547
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration> {
545548
if let Some(mut secs) = self.secs.checked_sub(rhs.secs) {
546549
let nanos = if self.nanos >= rhs.nanos {
@@ -573,7 +576,7 @@ impl Duration {
573576
#[must_use = "this returns the result of the operation, \
574577
without modifying the original"]
575578
#[inline]
576-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
579+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
577580
pub const fn saturating_sub(self, rhs: Duration) -> Duration {
578581
match self.checked_sub(rhs) {
579582
Some(res) => res,
@@ -598,7 +601,8 @@ impl Duration {
598601
#[must_use = "this returns the result of the operation, \
599602
without modifying the original"]
600603
#[inline]
601-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
604+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
605+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
602606
pub const fn checked_mul(self, rhs: u32) -> Option<Duration> {
603607
// Multiply nanoseconds as u64, because it cannot overflow that way.
604608
let total_nanos = self.nanos as u64 * rhs as u64;
@@ -629,7 +633,7 @@ impl Duration {
629633
#[must_use = "this returns the result of the operation, \
630634
without modifying the original"]
631635
#[inline]
632-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
636+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
633637
pub const fn saturating_mul(self, rhs: u32) -> Duration {
634638
match self.checked_mul(rhs) {
635639
Some(res) => res,
@@ -655,7 +659,8 @@ impl Duration {
655659
#[must_use = "this returns the result of the operation, \
656660
without modifying the original"]
657661
#[inline]
658-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
662+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
663+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
659664
pub const fn checked_div(self, rhs: u32) -> Option<Duration> {
660665
if rhs != 0 {
661666
let secs = self.secs / (rhs as u64);
@@ -683,7 +688,7 @@ impl Duration {
683688
#[stable(feature = "duration_float", since = "1.38.0")]
684689
#[must_use]
685690
#[inline]
686-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
691+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
687692
pub const fn as_secs_f64(&self) -> f64 {
688693
(self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64)
689694
}
@@ -702,7 +707,7 @@ impl Duration {
702707
#[stable(feature = "duration_float", since = "1.38.0")]
703708
#[must_use]
704709
#[inline]
705-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
710+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
706711
pub const fn as_secs_f32(&self) -> f32 {
707712
(self.secs as f32) + (self.nanos as f32) / (NANOS_PER_SEC as f32)
708713
}
@@ -723,7 +728,7 @@ impl Duration {
723728
#[stable(feature = "duration_float", since = "1.38.0")]
724729
#[must_use]
725730
#[inline]
726-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
731+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
727732
pub const fn from_secs_f64(secs: f64) -> Duration {
728733
match Duration::try_from_secs_f64(secs) {
729734
Ok(v) => v,
@@ -784,7 +789,7 @@ impl Duration {
784789
#[stable(feature = "duration_float", since = "1.38.0")]
785790
#[must_use]
786791
#[inline]
787-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
792+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
788793
pub const fn from_secs_f32(secs: f32) -> Duration {
789794
match Duration::try_from_secs_f32(secs) {
790795
Ok(v) => v,
@@ -846,7 +851,7 @@ impl Duration {
846851
#[must_use = "this returns the result of the operation, \
847852
without modifying the original"]
848853
#[inline]
849-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
854+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
850855
pub const fn mul_f64(self, rhs: f64) -> Duration {
851856
Duration::from_secs_f64(rhs * self.as_secs_f64())
852857
}
@@ -870,7 +875,7 @@ impl Duration {
870875
#[must_use = "this returns the result of the operation, \
871876
without modifying the original"]
872877
#[inline]
873-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
878+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
874879
pub const fn mul_f32(self, rhs: f32) -> Duration {
875880
Duration::from_secs_f32(rhs * self.as_secs_f32())
876881
}
@@ -893,7 +898,7 @@ impl Duration {
893898
#[must_use = "this returns the result of the operation, \
894899
without modifying the original"]
895900
#[inline]
896-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
901+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
897902
pub const fn div_f64(self, rhs: f64) -> Duration {
898903
Duration::from_secs_f64(self.as_secs_f64() / rhs)
899904
}
@@ -918,7 +923,7 @@ impl Duration {
918923
#[must_use = "this returns the result of the operation, \
919924
without modifying the original"]
920925
#[inline]
921-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
926+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
922927
pub const fn div_f32(self, rhs: f32) -> Duration {
923928
Duration::from_secs_f32(self.as_secs_f32() / rhs)
924929
}
@@ -938,7 +943,7 @@ impl Duration {
938943
#[must_use = "this returns the result of the operation, \
939944
without modifying the original"]
940945
#[inline]
941-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
946+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
942947
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
943948
self.as_secs_f64() / rhs.as_secs_f64()
944949
}
@@ -958,7 +963,7 @@ impl Duration {
958963
#[must_use = "this returns the result of the operation, \
959964
without modifying the original"]
960965
#[inline]
961-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
966+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
962967
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
963968
self.as_secs_f32() / rhs.as_secs_f32()
964969
}

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![feature(core_private_diy_float)]
2222
#![feature(dec2flt)]
2323
#![feature(div_duration)]
24-
#![feature(duration_consts_2)]
24+
#![feature(duration_consts_float)]
2525
#![feature(duration_constants)]
2626
#![feature(exact_size_is_empty)]
2727
#![feature(extern_types)]

0 commit comments

Comments
 (0)