@@ -25,15 +25,8 @@ impl Timespec {
25
25
Timespec { t : timespec { tv_sec, tv_nsec } }
26
26
}
27
27
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 {
37
30
Ok ( if self . t . tv_nsec >= other. t . tv_nsec {
38
31
Duration :: new (
39
32
( self . t . tv_sec - other. t . tv_sec ) as u64 ,
@@ -53,22 +46,20 @@ impl Timespec {
53
46
}
54
47
}
55
48
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 > {
58
50
let mut secs = self . t . tv_sec . checked_add_unsigned ( other. as_secs ( ) ) ?;
59
51
60
52
// Nano calculations can't overflow because nanos are <1B which fit
61
53
// 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 ( ) ;
65
57
secs = secs. checked_add ( 1 ) ?;
66
58
}
67
59
Some ( Timespec { t : timespec { tv_sec : secs, tv_nsec : nsec as _ } } )
68
60
}
69
61
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 > {
72
63
let mut secs = self . t . tv_sec . checked_sub_unsigned ( other. as_secs ( ) ) ?;
73
64
74
65
// Similar to above, nanos can't overflow.
@@ -222,18 +213,15 @@ impl SystemTime {
222
213
SystemTime ( time)
223
214
}
224
215
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 > {
227
217
self . 0 . sub_timespec ( & other. 0 )
228
218
}
229
219
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 > {
232
221
Some ( SystemTime ( self . 0 . checked_add_duration ( other) ?) )
233
222
}
234
223
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 > {
237
225
Some ( SystemTime ( self . 0 . checked_sub_duration ( other) ?) )
238
226
}
239
227
}
0 commit comments