Skip to content

Commit 98669c5

Browse files
committed
fix: add rust-fix annotation to unckd. duration subtr. lint test
1 parent e5d85f1 commit 98669c5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

tests/ui/unchecked_duration_subtraction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
#![warn(clippy::unchecked_duration_subtraction)]
23

34
use std::time::{Duration, Instant};

tests/ui/unchecked_duration_subtraction.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
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
33
|
44
LL | let _ = _first - second;
55
| ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();`
66
|
77
= note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
88

99
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
1111
|
1212
LL | let _ = Instant::now() - Duration::from_secs(5);
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();`
1414

1515
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
1717
|
1818
LL | let _ = _first - Duration::from_secs(5);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();`
2020

2121
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
2323
|
2424
LL | let _ = Instant::now() - second;
2525
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();`

0 commit comments

Comments
 (0)