Skip to content

Commit 04e24ae

Browse files
authored
Rollup merge of #83020 - hi-rustin:rustin-patch-enum, r=lcnr
Emit the enum range assumption if the range only contains one element close #82871
2 parents 7f319c7 + d180f91 commit 04e24ae

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
325325

326326
let er = scalar.valid_range_exclusive(bx.cx());
327327
if er.end != er.start
328-
&& scalar.valid_range.end() > scalar.valid_range.start()
328+
&& scalar.valid_range.end() >= scalar.valid_range.start()
329329
{
330330
// We want `table[e as usize ± k]` to not
331331
// have bound checks, and this is the most
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -O
2+
// min-llvm-version: 11.0
3+
4+
#![crate_type = "lib"]
5+
6+
#[repr(C)]
7+
pub enum E {
8+
A,
9+
}
10+
11+
// CHECK-LABEL: @index
12+
#[no_mangle]
13+
pub fn index(x: &[u32; 3], ind: E) -> u32{
14+
// CHECK-NOT: panic_bounds_check
15+
x[ind as usize]
16+
}

0 commit comments

Comments
 (0)