New to Rust, surprised by runtime panic

59 points waterproofsocks

I'm an experienced programmer but very new to Rust and am still learning where all the resources are for answering questions like this. I am working on a simple starter project to learn the basics, and came across a surprising runtime panic the compiler didn't catch. I'm wondering why, considering this 'index out of bounds' error looks so easy on the surface to verify at compile time. Am I just missing some compiler flags to add these warnings/errors?

fn index_out_of_bounds() {
    let array_of_one = [1];
    for i in 0..2 {
        println!("{}", array_of_one[i]);
    }
}