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
12#![ warn( clippy:: unchecked_duration_subtraction) ]
23
34use std:: time:: { Duration , Instant } ;
Original file line number Diff line number Diff line change 11error: unchecked subtraction of a 'Duration' from an 'Instant'
2- --> $DIR/unchecked_duration_subtraction.rs:9 :13
2+ --> $DIR/unchecked_duration_subtraction.rs:10 :13
33 |
44LL | let _ = _first - second;
55 | ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();`
66 |
77 = note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
88
99error: unchecked subtraction of a 'Duration' from an 'Instant'
10- --> $DIR/unchecked_duration_subtraction.rs:11 :13
10+ --> $DIR/unchecked_duration_subtraction.rs:12 :13
1111 |
1212LL | let _ = Instant::now() - Duration::from_secs(5);
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();`
1414
1515error: unchecked subtraction of a 'Duration' from an 'Instant'
16- --> $DIR/unchecked_duration_subtraction.rs:13 :13
16+ --> $DIR/unchecked_duration_subtraction.rs:14 :13
1717 |
1818LL | let _ = _first - Duration::from_secs(5);
1919 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();`
2020
2121error: unchecked subtraction of a 'Duration' from an 'Instant'
22- --> $DIR/unchecked_duration_subtraction.rs:15 :13
22+ --> $DIR/unchecked_duration_subtraction.rs:16 :13
2323 |
2424LL | let _ = Instant::now() - second;
2525 | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();`
You can’t perform that action at this time.
0 commit comments