Skip to content

Commit 14bb025

Browse files
committed
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.
1 parent 7fbd4ce commit 14bb025

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

Diff for: library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
#![feature(const_type_id)]
132132
#![feature(const_type_name)]
133133
#![feature(const_default_impls)]
134-
#![feature(duration_consts_2)]
134+
#![feature(duration_consts_float)]
135135
#![feature(ptr_metadata)]
136136
#![feature(slice_ptr_get)]
137137
#![feature(variant_count)]

Diff for: 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,
@@ -477,7 +478,8 @@ impl Duration {
477478
#[must_use = "this returns the result of the operation, \
478479
without modifying the original"]
479480
#[inline]
480-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
481+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
482+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
481483
pub const fn checked_add(self, rhs: Duration) -> Option<Duration> {
482484
if let Some(mut secs) = self.secs.checked_add(rhs.secs) {
483485
let mut nanos = self.nanos + rhs.nanos;
@@ -512,7 +514,7 @@ impl Duration {
512514
#[must_use = "this returns the result of the operation, \
513515
without modifying the original"]
514516
#[inline]
515-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
517+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
516518
pub const fn saturating_add(self, rhs: Duration) -> Duration {
517519
match self.checked_add(rhs) {
518520
Some(res) => res,
@@ -537,7 +539,8 @@ impl Duration {
537539
#[must_use = "this returns the result of the operation, \
538540
without modifying the original"]
539541
#[inline]
540-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
542+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
543+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
541544
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration> {
542545
if let Some(mut secs) = self.secs.checked_sub(rhs.secs) {
543546
let nanos = if self.nanos >= rhs.nanos {
@@ -570,7 +573,7 @@ impl Duration {
570573
#[must_use = "this returns the result of the operation, \
571574
without modifying the original"]
572575
#[inline]
573-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
576+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
574577
pub const fn saturating_sub(self, rhs: Duration) -> Duration {
575578
match self.checked_sub(rhs) {
576579
Some(res) => res,
@@ -595,7 +598,8 @@ impl Duration {
595598
#[must_use = "this returns the result of the operation, \
596599
without modifying the original"]
597600
#[inline]
598-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
601+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
602+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
599603
pub const fn checked_mul(self, rhs: u32) -> Option<Duration> {
600604
// Multiply nanoseconds as u64, because it cannot overflow that way.
601605
let total_nanos = self.nanos as u64 * rhs as u64;
@@ -626,7 +630,7 @@ impl Duration {
626630
#[must_use = "this returns the result of the operation, \
627631
without modifying the original"]
628632
#[inline]
629-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
633+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
630634
pub const fn saturating_mul(self, rhs: u32) -> Duration {
631635
match self.checked_mul(rhs) {
632636
Some(res) => res,
@@ -652,7 +656,8 @@ impl Duration {
652656
#[must_use = "this returns the result of the operation, \
653657
without modifying the original"]
654658
#[inline]
655-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
659+
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
660+
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_panic))]
656661
pub const fn checked_div(self, rhs: u32) -> Option<Duration> {
657662
if rhs != 0 {
658663
let secs = self.secs / (rhs as u64);
@@ -680,7 +685,7 @@ impl Duration {
680685
#[stable(feature = "duration_float", since = "1.38.0")]
681686
#[must_use]
682687
#[inline]
683-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
688+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
684689
pub const fn as_secs_f64(&self) -> f64 {
685690
(self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64)
686691
}
@@ -699,7 +704,7 @@ impl Duration {
699704
#[stable(feature = "duration_float", since = "1.38.0")]
700705
#[must_use]
701706
#[inline]
702-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
707+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
703708
pub const fn as_secs_f32(&self) -> f32 {
704709
(self.secs as f32) + (self.nanos as f32) / (NANOS_PER_SEC as f32)
705710
}
@@ -720,7 +725,7 @@ impl Duration {
720725
#[stable(feature = "duration_float", since = "1.38.0")]
721726
#[must_use]
722727
#[inline]
723-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
728+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
724729
pub const fn from_secs_f64(secs: f64) -> Duration {
725730
match Duration::try_from_secs_f64(secs) {
726731
Ok(v) => v,
@@ -782,7 +787,7 @@ impl Duration {
782787
#[stable(feature = "duration_float", since = "1.38.0")]
783788
#[must_use]
784789
#[inline]
785-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
790+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
786791
pub const fn from_secs_f32(secs: f32) -> Duration {
787792
match Duration::try_from_secs_f32(secs) {
788793
Ok(v) => v,
@@ -845,7 +850,7 @@ impl Duration {
845850
#[must_use = "this returns the result of the operation, \
846851
without modifying the original"]
847852
#[inline]
848-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
853+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
849854
pub const fn mul_f64(self, rhs: f64) -> Duration {
850855
Duration::from_secs_f64(rhs * self.as_secs_f64())
851856
}
@@ -869,7 +874,7 @@ impl Duration {
869874
#[must_use = "this returns the result of the operation, \
870875
without modifying the original"]
871876
#[inline]
872-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
877+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
873878
pub const fn mul_f32(self, rhs: f32) -> Duration {
874879
Duration::from_secs_f32(rhs * self.as_secs_f32())
875880
}
@@ -892,7 +897,7 @@ impl Duration {
892897
#[must_use = "this returns the result of the operation, \
893898
without modifying the original"]
894899
#[inline]
895-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
900+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
896901
pub const fn div_f64(self, rhs: f64) -> Duration {
897902
Duration::from_secs_f64(self.as_secs_f64() / rhs)
898903
}
@@ -917,7 +922,7 @@ impl Duration {
917922
#[must_use = "this returns the result of the operation, \
918923
without modifying the original"]
919924
#[inline]
920-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
925+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
921926
pub const fn div_f32(self, rhs: f32) -> Duration {
922927
Duration::from_secs_f32(self.as_secs_f32() / rhs)
923928
}
@@ -937,7 +942,7 @@ impl Duration {
937942
#[must_use = "this returns the result of the operation, \
938943
without modifying the original"]
939944
#[inline]
940-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
945+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
941946
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
942947
self.as_secs_f64() / rhs.as_secs_f64()
943948
}
@@ -957,7 +962,7 @@ impl Duration {
957962
#[must_use = "this returns the result of the operation, \
958963
without modifying the original"]
959964
#[inline]
960-
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
965+
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
961966
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {
962967
self.as_secs_f32() / rhs.as_secs_f32()
963968
}

Diff for: library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![feature(core_private_diy_float)]
2121
#![feature(dec2flt)]
2222
#![feature(div_duration)]
23-
#![feature(duration_consts_2)]
23+
#![feature(duration_consts_float)]
2424
#![feature(duration_constants)]
2525
#![feature(exact_size_is_empty)]
2626
#![feature(extern_types)]

0 commit comments

Comments
 (0)