diff options
Diffstat (limited to 'src/tools/clippy/src/docs/manual_instant_elapsed.txt')
-rw-r--r-- | src/tools/clippy/src/docs/manual_instant_elapsed.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/manual_instant_elapsed.txt b/src/tools/clippy/src/docs/manual_instant_elapsed.txt new file mode 100644 index 000000000..dde3d493c --- /dev/null +++ b/src/tools/clippy/src/docs/manual_instant_elapsed.txt @@ -0,0 +1,21 @@ +### What it does +Lints subtraction between `Instant::now()` and another `Instant`. + +### Why is this bad? +It is easy to accidentally write `prev_instant - Instant::now()`, which will always be 0ns +as `Instant` subtraction saturates. + +`prev_instant.elapsed()` also more clearly signals intention. + +### Example +``` +use std::time::Instant; +let prev_instant = Instant::now(); +let duration = Instant::now() - prev_instant; +``` +Use instead: +``` +use std::time::Instant; +let prev_instant = Instant::now(); +let duration = prev_instant.elapsed(); +```
\ No newline at end of file |