@@ -38,18 +38,15 @@ impl SystemTime {
38
38
SystemTime { t : Timespec :: now ( libc:: CLOCK_REALTIME ) }
39
39
}
40
40
41
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
42
- pub const fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
41
+ pub fn sub_time ( & self , other : & SystemTime ) -> Result < Duration , Duration > {
43
42
self . t . sub_timespec ( & other. t )
44
43
}
45
44
46
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
47
- pub const fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
45
+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < SystemTime > {
48
46
Some ( SystemTime { t : self . t . checked_add_duration ( other) ? } )
49
47
}
50
48
51
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
52
- pub const fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
49
+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < SystemTime > {
53
50
Some ( SystemTime { t : self . t . checked_sub_duration ( other) ? } )
54
51
}
55
52
}
@@ -136,15 +133,8 @@ impl Timespec {
136
133
Timespec :: new ( t. tv_sec as i64 , t. tv_nsec as i64 ) . unwrap ( )
137
134
}
138
135
139
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
140
- pub const fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
141
- // FIXME: const PartialOrd
142
- let mut cmp = self . tv_sec - other. tv_sec ;
143
- if cmp == 0 {
144
- cmp = self . tv_nsec . as_inner ( ) as i64 - other. tv_nsec . as_inner ( ) as i64 ;
145
- }
146
-
147
- if cmp >= 0 {
136
+ pub fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
137
+ if self >= other {
148
138
// NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM
149
139
// to optimize it into a branchless form (see also #75545):
150
140
//
@@ -179,8 +169,7 @@ impl Timespec {
179
169
}
180
170
}
181
171
182
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
183
- pub const fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
172
+ pub fn checked_add_duration ( & self , other : & Duration ) -> Option < Timespec > {
184
173
let mut secs = self . tv_sec . checked_add_unsigned ( other. as_secs ( ) ) ?;
185
174
186
175
// Nano calculations can't overflow because nanos are <1B which fit
@@ -190,11 +179,10 @@ impl Timespec {
190
179
nsec -= NSEC_PER_SEC as u32 ;
191
180
secs = secs. checked_add ( 1 ) ?;
192
181
}
193
- Some ( unsafe { Timespec :: new_unchecked ( secs, nsec as i64 ) } )
182
+ Some ( unsafe { Timespec :: new_unchecked ( secs, nsec. into ( ) ) } )
194
183
}
195
184
196
- #[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
197
- pub const fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
185
+ pub fn checked_sub_duration ( & self , other : & Duration ) -> Option < Timespec > {
198
186
let mut secs = self . tv_sec . checked_sub_unsigned ( other. as_secs ( ) ) ?;
199
187
200
188
// Similar to above, nanos can't overflow.
@@ -203,7 +191,7 @@ impl Timespec {
203
191
nsec += NSEC_PER_SEC as i32 ;
204
192
secs = secs. checked_sub ( 1 ) ?;
205
193
}
206
- Some ( unsafe { Timespec :: new_unchecked ( secs, nsec as i64 ) } )
194
+ Some ( unsafe { Timespec :: new_unchecked ( secs, nsec. into ( ) ) } )
207
195
}
208
196
209
197
#[ allow( dead_code) ]
0 commit comments