File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change
1
+ // run-rustfix
2
+ #![warn(clippy::unchecked_duration_subtraction)]
3
+
4
+ use std::time::{Duration, Instant};
5
+
6
+ fn main() {
7
+ let _first = Instant::now();
8
+ let second = Duration::from_secs(3);
9
+
10
+ let _ = _first.checked_sub(second).unwrap();;
11
+
12
+ let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap();;
13
+
14
+ let _ = _first.checked_sub(Duration::from_secs(5)).unwrap();;
15
+
16
+ let _ = Instant::now().checked_sub(second).unwrap();;
17
+ }
Original file line number Diff line number Diff line change
1
+ // run-rustfix
1
2
#![ warn( clippy:: unchecked_duration_subtraction) ]
2
3
3
4
use std:: time:: { Duration , Instant } ;
Original file line number Diff line number Diff line change 1
1
error: unchecked subtraction of a 'Duration' from an 'Instant'
2
- --> $DIR/unchecked_duration_subtraction.rs:9 :13
2
+ --> $DIR/unchecked_duration_subtraction.rs:10 :13
3
3
|
4
4
LL | let _ = _first - second;
5
5
| ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();`
6
6
|
7
7
= note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
8
8
9
9
error: unchecked subtraction of a 'Duration' from an 'Instant'
10
- --> $DIR/unchecked_duration_subtraction.rs:11 :13
10
+ --> $DIR/unchecked_duration_subtraction.rs:12 :13
11
11
|
12
12
LL | let _ = Instant::now() - Duration::from_secs(5);
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();`
14
14
15
15
error: unchecked subtraction of a 'Duration' from an 'Instant'
16
- --> $DIR/unchecked_duration_subtraction.rs:13 :13
16
+ --> $DIR/unchecked_duration_subtraction.rs:14 :13
17
17
|
18
18
LL | let _ = _first - Duration::from_secs(5);
19
19
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();`
20
20
21
21
error: unchecked subtraction of a 'Duration' from an 'Instant'
22
- --> $DIR/unchecked_duration_subtraction.rs:15 :13
22
+ --> $DIR/unchecked_duration_subtraction.rs:16 :13
23
23
|
24
24
LL | let _ = Instant::now() - second;
25
25
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();`
You can’t perform that action at this time.
0 commit comments