We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
unchecked_duration_subtraction
1 parent 3b4e42b commit b280dbeCopy full SHA for b280dbe
src/docs/unchecked_duration_subtraction.txt
@@ -0,0 +1,19 @@
1
+### What it does
2
+Finds patterns of unchecked subtraction of [`Duration`] from [`Instant::now()`].
3
+
4
+### Why is this bad?
5
+Unchecked subtraction could cause underflow on certain platforms, leading to bugs and/or
6
+unintentional panics.
7
8
+### Example
9
+```
10
+let time_passed = Instant::now() - Duration::from_secs(5);
11
12
13
+Use instead:
14
15
+let time_passed = Instant::now().checked_sub(Duration::from_secs(5));
16
17
18
+[`Duration`]: std::time::Duration
19
+[`Instant::now()`]: std::time::Instant::now;
0 commit comments