@@ -25,15 +25,8 @@ impl Timespec {
2525 Timespec { t : timespec { tv_sec, tv_nsec } }
2626 }
2727
28- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
29- const fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
30- // FIXME: const PartialOrd
31- let mut cmp = self . t . tv_sec - other. t . tv_sec ;
32- if cmp == 0 {
33- cmp = self . t . tv_nsec as i64 - other. t . tv_nsec as i64 ;
34- }
35-
36- if cmp >= 0 {
28+ fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
29+ if self >= other {
3730 Ok ( if self . t . tv_nsec >= other. t . tv_nsec {
3831 Duration :: new (
3932 ( self . t . tv_sec - other. t . tv_sec ) as u64 ,
@@ -53,22 +46,20 @@ impl Timespec {
5346 }
5447 }
5548
56- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
57- const fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
49+ fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
5850 let mut secs = self . t . tv_sec . checked_add_unsigned ( other. as_secs ( ) ) ?;
5951
6052 // Nano calculations can't overflow because nanos are <1B which fit
6153 // in a u32.
62- let mut nsec = other. subsec_nanos ( ) + self . t . tv_nsec as u32 ;
63- if nsec >= NSEC_PER_SEC as u32 {
64- nsec -= NSEC_PER_SEC as u32 ;
54+ let mut nsec = other. subsec_nanos ( ) + u32 :: try_from ( self . t . tv_nsec ) . unwrap ( ) ;
55+ if nsec >= NSEC_PER_SEC . try_into ( ) . unwrap ( ) {
56+ nsec -= u32:: try_from ( NSEC_PER_SEC ) . unwrap ( ) ;
6557 secs = secs. checked_add ( 1 ) ?;
6658 }
6759 Some ( Timespec { t : timespec { tv_sec : secs, tv_nsec : nsec as _ } } )
6860 }
6961
70- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
71- const fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
62+ fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
7263 let mut secs = self . t . tv_sec . checked_sub_unsigned ( other. as_secs ( ) ) ?;
7364
7465 // Similar to above, nanos can't overflow.
@@ -222,18 +213,15 @@ impl SystemTime {
222213 SystemTime ( time)
223214 }
224215
225- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
226- pub const fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
216+ pub fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
227217 self . 0 . sub_timespec ( & other. 0 )
228218 }
229219
230- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
231- pub const fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
220+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
232221 Some ( SystemTime ( self . 0 . checked_add_duration ( other) ?) )
233222 }
234223
235- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
236- pub const fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
224+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
237225 Some ( SystemTime ( self . 0 . checked_sub_duration ( other) ?) )
238226 }
239227}
0 commit comments