File tree 1 file changed +28
-8
lines changed
1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -8,22 +8,42 @@ use rustc_session::declare_lint_pass;
8
8
9
9
declare_clippy_lint ! {
10
10
/// ### What it does
11
- /// Detects classic underflow/overflow checks.
11
+ /// Detects C-style underflow/overflow checks.
12
12
///
13
13
/// ### Why is this bad?
14
- /// Most classic C underflow/overflow checks will fail in
15
- /// Rust. Users can use functions like `overflowing_*` and `wrapping_*` instead .
14
+ /// These checks will, by default, panic in debug builds rather than check
15
+ /// whether the operation caused an overflow .
16
16
///
17
17
/// ### Example
18
18
/// ```no_run
19
- /// # let a = 1;
20
- /// # let b = 2;
21
- /// a + b < a;
19
+ /// # let a = 1i32;
20
+ /// # let b = 2i32;
21
+ /// if a + b < a {
22
+ /// // handle overflow
23
+ /// }
24
+ /// ```
25
+ ///
26
+ /// Use instead:
27
+ /// ```no_run
28
+ /// # let a = 1i32;
29
+ /// # let b = 2i32;
30
+ /// if a.checked_add(b).is_none() {
31
+ /// // handle overflow
32
+ /// }
33
+ /// ```
34
+ ///
35
+ /// Or:
36
+ /// ```no_run
37
+ /// # let a = 1i32;
38
+ /// # let b = 2i32;
39
+ /// if a.overflowing_add(b).1 {
40
+ /// // handle overflow
41
+ /// }
22
42
/// ```
23
43
#[ clippy:: version = "pre 1.29.0" ]
24
44
pub PANICKING_OVERFLOW_CHECKS ,
25
- complexity ,
26
- "overflow checks inspired by C which are likely to panic "
45
+ correctness ,
46
+ "overflow checks which will panic in debug mode "
27
47
}
28
48
29
49
declare_lint_pass ! ( PanickingOverflowChecks => [ PANICKING_OVERFLOW_CHECKS ] ) ;
You can’t perform that action at this time.
0 commit comments