diff options
| author | Nadir Fejzic <nadirfejzo@gmail.com> | 2022-10-01 16:50:45 +0200 |
|---|---|---|
| committer | Nadir Fejzic <nadirfejzo@gmail.com> | 2022-11-10 15:46:56 +0100 |
| commit | b280dbe5f73286a3f2a02e93c6c3e42181ec8aca (patch) | |
| tree | 60bea6adf568396c9392c48f4017bcb222a5dec7 /src/docs | |
| parent | 3b4e42b91b0df11c43983c6fe67bb971f472aa3f (diff) | |
docs: add docs for `unchecked_duration_subtraction` lint
Diffstat (limited to 'src/docs')
| -rw-r--r-- | src/docs/unchecked_duration_subtraction.txt | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/docs/unchecked_duration_subtraction.txt b/src/docs/unchecked_duration_subtraction.txt new file mode 100644 index 00000000000..6b9c9308c87 --- /dev/null +++ b/src/docs/unchecked_duration_subtraction.txt @@ -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; \ No newline at end of file |
