Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

unfit in i8 - run time - overflow

fn main() {
    let mut num: i8 = 126;
    println!("{num}");

    num += 1;
    println!("{num}");

    num += 1;
    println!("{num}");
}
cargo run
126
127
thread 'main' panicked at 'attempt to add with overflow', examples/intro/overflow.rs:6:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  • In debug mode panic!
cargo run --release
126
127
-128