File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -516,6 +516,7 @@ docs! {
516
516
"try_err" ,
517
517
"type_complexity" ,
518
518
"type_repetition_in_bounds" ,
519
+ "unchecked_duration_subtraction" ,
519
520
"undocumented_unsafe_blocks" ,
520
521
"undropped_manually_drops" ,
521
522
"unicode_not_nfc" ,
Original file line number Diff line number Diff line change
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;
You can’t perform that action at this time.
0 commit comments