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