docs: add docs for unchecked_duration_subtraction lint

This commit is contained in:
Nadir Fejzic 2022-10-01 16:50:45 +02:00
parent 3b4e42b91b
commit b280dbe5f7

View File

@ -0,0 +1,19 @@
### What it does
Finds patterns of unchecked subtraction of [`Duration`] from [`Instant::now()`].
### Why is this bad?
Unchecked subtraction could cause underflow on certain platforms, leading to bugs and/or
unintentional panics.
### Example
```
let time_passed = Instant::now() - Duration::from_secs(5);
```
Use instead:
```
let time_passed = Instant::now().checked_sub(Duration::from_secs(5));
```
[`Duration`]: std::time::Duration
[`Instant::now()`]: std::time::Instant::now;