mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
fix: add rust-fix annotation to unckd. duration subtr. lint test
This commit is contained in:
parent
852d802451
commit
62ab4fb9c2
3 changed files with 22 additions and 4 deletions
17
tests/ui/unchecked_duration_subtraction.fixed
Normal file
17
tests/ui/unchecked_duration_subtraction.fixed
Normal 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();;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
// run-rustfix
|
||||
#![warn(clippy::unchecked_duration_subtraction)]
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
|
|
@ -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();`
|
||||
|
|
Loading…
Reference in a new issue