extern crate test;
fn main() {
let mut v = vec![1i32, 2, 3, 4, 5];
let vlen = v.len();
for i in range(0, vlen) {
let x = &mut v[i];
test::black_box(x); // do some work with x
}
}
Compiling this file with rustc -O, the compiler not only gets rid of the bounds checking, it gets rid of the loop altogether by unrolling it completely.LLVM IR: https://gist.github.com/veddan/1535a8718cf2c85006ea