]> git.lizzy.rs Git - rust.git/blob - src/docs/arithmetic.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / arithmetic.txt
1 ### What it does
2 Checks for any kind of arithmetic operation of any type.
3
4 Operators like `+`, `-`, `*` or `<<` are usually capable of overflowing according to the [Rust
5 Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
6 or can panic (`/`, `%`). Known safe built-in types like `Wrapping` or `Saturing` are filtered
7 away.
8
9 ### Why is this bad?
10 Integer overflow will trigger a panic in debug builds or will wrap in
11 release mode. Division by zero will cause a panic in either mode. In some applications one
12 wants explicitly checked, wrapping or saturating arithmetic.
13
14 #### Example
15 ```
16 a + 1;
17 ```
18
19 Third-party types also tend to overflow.
20
21 #### Example
22 ```
23 use rust_decimal::Decimal;
24 let _n = Decimal::MAX + Decimal::MAX;
25 ```
26
27 ### Allowed types
28 Custom allowed types can be specified through the "arithmetic-allowed" filter.