why does optimization removes overflow checks?
consider below testcase
$cat test.rs
fn fibonacci(n: u32) -> u32 {
    let mut f:u32 = 0;
    let mut s:u32 = 1;
    let mut next: u32 =f+s;
    for _ in 1..n {
                f = s;
                s= next;
               next=f+s;
    }
    next
}
fn main() {
println!("{}",fibonacci(100));
}

$rustc test.rs -C opt-level=1
$./test
2425370821

$rustc test.rs -C opt-level=0
$./test
thread 'main' panicked at 'attempt to add with overflow', p11.rs:11:7
note: run with `RUST_BACKTRACE=1` environment variable to display a
backtrace.

./Kamlesh
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to