Rust compiler fails to eliminate bounds check when array is indexed by an enum cast to usize
Compiler explorer: https://godbolt.org/z/4o5cqT1eK
Code
pub enum Enum {
A, B, C
}
pub fn func(inbounds: Enum, array: &[i16; 3]) -> i16 {
array[inbounds as usize]
}
I expected the compiler to remove the bounds checks like it did previously however it failed to do so.
Version it worked on
It most recently worked on: Rust 1.63.0
Version with regression
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-unknown-linux-gnu
release: 1.64.0
LLVM version: 14.0.6
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
Rust compiler fails to eliminate bounds check when array is indexed by an enum cast to usize
Compiler explorer: https://godbolt.org/z/4o5cqT1eK
Code
I expected the compiler to remove the bounds checks like it did previously however it failed to do so.
Version it worked on
It most recently worked on: Rust 1.63.0
Version with regression
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged