fix: add rust-fix annotation to unckd. duration subtr. lint test

This commit is contained in:
Nadir Fejzic 2022-11-08 10:22:58 +01:00
parent 852d802451
commit 62ab4fb9c2
3 changed files with 22 additions and 4 deletions

View File

@ -0,0 +1,17 @@
// run-rustfix
#![warn(clippy::unchecked_duration_subtraction)]
use std::time::{Duration, Instant};
fn main() {
let _first = Instant::now();
let second = Duration::from_secs(3);
let _ = _first.checked_sub(second).unwrap();;
let _ = Instant::now().checked_sub(Duration::from_secs(5)).unwrap();;
let _ = _first.checked_sub(Duration::from_secs(5)).unwrap();;
let _ = Instant::now().checked_sub(second).unwrap();;
}

View File

@ -1,3 +1,4 @@
// run-rustfix
#![warn(clippy::unchecked_duration_subtraction)]
use std::time::{Duration, Instant};

View File

@ -1,5 +1,5 @@
error: unchecked subtraction of a 'Duration' from an 'Instant'
--> $DIR/unchecked_duration_subtraction.rs:9:13
--> $DIR/unchecked_duration_subtraction.rs:10:13
|
LL | let _ = _first - second;
| ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();`
@ -7,19 +7,19 @@ LL | let _ = _first - second;
= note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
error: unchecked subtraction of a 'Duration' from an 'Instant'
--> $DIR/unchecked_duration_subtraction.rs:11:13
--> $DIR/unchecked_duration_subtraction.rs:12:13
|
LL | let _ = Instant::now() - Duration::from_secs(5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();`
error: unchecked subtraction of a 'Duration' from an 'Instant'
--> $DIR/unchecked_duration_subtraction.rs:13:13
--> $DIR/unchecked_duration_subtraction.rs:14:13
|
LL | let _ = _first - Duration::from_secs(5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();`
error: unchecked subtraction of a 'Duration' from an 'Instant'
--> $DIR/unchecked_duration_subtraction.rs:15:13
--> $DIR/unchecked_duration_subtraction.rs:16:13
|
LL | let _ = Instant::now() - second;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();`