(I'm using Rust 1.44.1)
The following example fails to build (debug mode) because of arithmetic overflow (and I understand why) :
fn main() {
let i: u8 = 255 + 1;
}
error: this arithmetic operation will overflow
--> src/main.rs:2:17
|
2 | let i: u8 = 255 + 1;
| ^^^^^^^ attempt to add with overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
While this example builds correctly :
fn main() {
let i: u8 = 255;
let _j: u8 = i + 1;
}
Since i
is immutable, I would have expected the same error as the first example.
Am I missing something or this is something not handled by the compiler ?