]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/manual_instant_elapsed.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / manual_instant_elapsed.txt
1 ### What it does
2 Lints subtraction between `Instant::now()` and another `Instant`.
3
4 ### Why is this bad?
5 It is easy to accidentally write `prev_instant - Instant::now()`, which will always be 0ns
6 as `Instant` subtraction saturates.
7
8 `prev_instant.elapsed()` also more clearly signals intention.
9
10 ### Example
11 ```
12 use std::time::Instant;
13 let prev_instant = Instant::now();
14 let duration = Instant::now() - prev_instant;
15 ```
16 Use instead:
17 ```
18 use std::time::Instant;
19 let prev_instant = Instant::now();
20 let duration = prev_instant.elapsed();
21 ```