Closed
Description
This is modified code from a real regression in my code:
#![allow(unused_variables)]
fn main() {
const N: usize = 1_000;
const M: usize = 4;
const V: [u32; M] = [1, 2, 3, 4];
let x = if N <= M {
V[N - 1]
} else {
0
};
}
warning: this expression will panic at run-time
--> C:\lavoro\bugs\test.rs:9:9
|
9 | INIT[N - 1]
| ^^^^^^^^^^^ index out of bounds: the len is 4 but the index is 999
rustc 1.25.0-nightly (f62f77403 2018-01-10)
binary: rustc
commit-hash: f62f774035735a06c880c48c0b9017fcc0577e33
commit-date: 2018-01-10
host: x86_64-pc-windows-gnu
release: 1.25.0-nightly
LLVM version: 4.0
D language and C++17 avoid such problems using "static if" and "if constexpr".