Compiling in Release Mode Still Panic, Where's Complement Wrapping?

When you’re compiling in release mode with the --release flag, Rust does not include checks for integer overflow that cause panics. Instead, if overflow occurs, Rust performs two’s complement wrapping. - The book.

here's my code:

fn main() {
   let guess: i8 = "128".parse().expect("ahaa err");;

then i run cargo run --release, unfortunately my code is still panicked. Why rust does not performs its complement wrapping?

thank you.

The quoted part of the book is referring to operations like +, not parsing. The parsing implementation does checked addition and return an error on overflow.

If you need to parse-then-overflow, parse as a larger integer type and then convert it.

1 Like

thank you, got it.