File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -28,20 +28,20 @@ impl Timespec {
28
28
#[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
29
29
const fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
30
30
// FIXME: const PartialOrd
31
- let mut cmp = self . t . tv_sec - other. t . tv_sec ;
31
+ let mut cmp = self . t . tv_sec . saturating_sub ( other. t . tv_sec ) ;
32
32
if cmp == 0 {
33
33
cmp = self . t . tv_nsec as i64 - other. t . tv_nsec as i64 ;
34
34
}
35
35
36
36
if cmp >= 0 {
37
37
Ok ( if self . t . tv_nsec >= other. t . tv_nsec {
38
38
Duration :: new (
39
- ( self . t . tv_sec - other. t . tv_sec ) as u64 ,
39
+ self . t . tv_sec . wrapping_sub ( other. t . tv_sec ) as u64 ,
40
40
( self . t . tv_nsec - other. t . tv_nsec ) as u32 ,
41
41
)
42
42
} else {
43
43
Duration :: new (
44
- ( self . t . tv_sec - 1 - other. t . tv_sec ) as u64 ,
44
+ self . t . tv_sec . wrapping_sub ( other. t . tv_sec ) as u64 - 1_u64 ,
45
45
( self . t . tv_nsec + NSEC_PER_SEC - other. t . tv_nsec ) as u32 ,
46
46
)
47
47
} )
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ impl SystemTime {
95
95
96
96
// Check if can be represented in UEFI
97
97
// FIXME: const PartialOrd
98
- let mut cmp = temp. as_secs ( ) - MAX_UEFI_TIME . 0 . as_secs ( ) ;
98
+ let mut cmp = temp. as_secs ( ) . saturating_sub ( MAX_UEFI_TIME . 0 . as_secs ( ) ) ;
99
99
if cmp == 0 {
100
100
cmp = temp. subsec_nanos ( ) as u64 - MAX_UEFI_TIME . 0 . subsec_nanos ( ) as u64 ;
101
101
}
Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ impl Timespec {
139
139
#[ rustc_const_unstable( feature = "const_system_time" , issue = "144517" ) ]
140
140
pub const fn sub_timespec ( & self , other : & Timespec ) -> Result < Duration , Duration > {
141
141
// FIXME: const PartialOrd
142
- let mut cmp = self . tv_sec - other. tv_sec ;
142
+ let mut cmp = self . tv_sec . saturating_sub ( other. tv_sec ) ;
143
143
if cmp == 0 {
144
144
cmp = self . tv_nsec . as_inner ( ) as i64 - other. tv_nsec . as_inner ( ) as i64 ;
145
145
}
@@ -160,12 +160,12 @@ impl Timespec {
160
160
// directly expresses the lower-cost behavior we want from it.
161
161
let ( secs, nsec) = if self . tv_nsec . as_inner ( ) >= other. tv_nsec . as_inner ( ) {
162
162
(
163
- ( self . tv_sec - other. tv_sec ) as u64 ,
163
+ self . tv_sec . wrapping_sub ( other. tv_sec ) as u64 ,
164
164
self . tv_nsec . as_inner ( ) - other. tv_nsec . as_inner ( ) ,
165
165
)
166
166
} else {
167
167
(
168
- ( self . tv_sec - other. tv_sec - 1 ) as u64 ,
168
+ self . tv_sec . wrapping_sub ( other. tv_sec ) as u64 - 1_u64 ,
169
169
self . tv_nsec . as_inner ( ) + ( NSEC_PER_SEC as u32 ) - other. tv_nsec . as_inner ( ) ,
170
170
)
171
171
} ;
You can’t perform that action at this time.
0 commit comments