mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
test: add tests for 'unchecked_duration_subtraction' lint
This commit is contained in:
parent
708c2d95c1
commit
3b4e42b91b
2 changed files with 48 additions and 0 deletions
16
tests/ui/unchecked_duration_subtraction.rs
Normal file
16
tests/ui/unchecked_duration_subtraction.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
#![warn(clippy::unchecked_duration_subtraction)]
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
fn main() {
|
||||
let _first = Instant::now();
|
||||
let second = Duration::from_secs(3);
|
||||
|
||||
let _ = _first - second;
|
||||
|
||||
let _ = Instant::now() - Duration::from_secs(5);
|
||||
|
||||
let _ = _first - Duration::from_secs(5);
|
||||
|
||||
let _ = Instant::now() - second;
|
||||
}
|
32
tests/ui/unchecked_duration_subtraction.stderr
Normal file
32
tests/ui/unchecked_duration_subtraction.stderr
Normal file
|
@ -0,0 +1,32 @@
|
|||
[clippy_lints/src/unchecked_duration_subtraction.rs:75] def = std::time::Instant
|
||||
error: unchecked subtraction of a 'Duration' from an 'Instant'
|
||||
--> $DIR/unchecked_duration_subtraction.rs:9:13
|
||||
|
|
||||
LL | let _ = _first - second;
|
||||
| ^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(second).unwrap();`
|
||||
|
|
||||
= note: `-D clippy::unchecked-duration-subtraction` implied by `-D warnings`
|
||||
|
||||
[clippy_lints/src/unchecked_duration_subtraction.rs:75] def = std::time::Instant
|
||||
error: unchecked subtraction of a 'Duration' from an 'Instant'
|
||||
--> $DIR/unchecked_duration_subtraction.rs:11:13
|
||||
|
|
||||
LL | let _ = Instant::now() - Duration::from_secs(5);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(Duration::from_secs(5)).unwrap();`
|
||||
|
||||
[clippy_lints/src/unchecked_duration_subtraction.rs:75] def = std::time::Instant
|
||||
error: unchecked subtraction of a 'Duration' from an 'Instant'
|
||||
--> $DIR/unchecked_duration_subtraction.rs:13:13
|
||||
|
|
||||
LL | let _ = _first - Duration::from_secs(5);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `_first.checked_sub(Duration::from_secs(5)).unwrap();`
|
||||
|
||||
[clippy_lints/src/unchecked_duration_subtraction.rs:75] def = std::time::Instant
|
||||
error: unchecked subtraction of a 'Duration' from an 'Instant'
|
||||
--> $DIR/unchecked_duration_subtraction.rs:15:13
|
||||
|
|
||||
LL | let _ = Instant::now() - second;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Instant::now().checked_sub(second).unwrap();`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
Loading…
Reference in a new issue