]> git.lizzy.rs Git - rust.git/blob - src/docs/integer_arithmetic.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / integer_arithmetic.txt
1 ### What it does
2 Checks for integer arithmetic operations which could overflow or panic.
3
4 Specifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable
5 of overflowing according to the [Rust
6 Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
7 or which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is
8 attempted.
9
10 ### Why is this bad?
11 Integer overflow will trigger a panic in debug builds or will wrap in
12 release mode. Division by zero will cause a panic in either mode. In some applications one
13 wants explicitly checked, wrapping or saturating arithmetic.
14
15 ### Example
16 ```
17 a + 1;
18 ```