Skip to content

Array indexed by enum cast to usize no longer has bounds check eliminated #102303

Closed
@jnlt3

Description

@jnlt3

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

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationC-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions