Skip to content

Commit ea9bd3b

Browse files
committed
Move panicking_overflow_checks into correctness and clean up docs.
1 parent 236d79c commit ea9bd3b

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

clippy_lints/src/panicking_overflow_checks.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,42 @@ use rustc_session::declare_lint_pass;
88

99
declare_clippy_lint! {
1010
/// ### What it does
11-
/// Detects classic underflow/overflow checks.
11+
/// Detects C-style underflow/overflow checks.
1212
///
1313
/// ### 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.
1616
///
1717
/// ### Example
1818
/// ```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+
/// }
2242
/// ```
2343
#[clippy::version = "pre 1.29.0"]
2444
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"
2747
}
2848

2949
declare_lint_pass!(PanickingOverflowChecks => [PANICKING_OVERFLOW_CHECKS]);

0 commit comments

Comments
 (0)