Skip to content

Commit 59d27a7

Browse files
committed
Rollup merge of rust-lang#28841 - jld:const-slice-ice, r=Aatch
This turned up as part of rust-lang#3170. When constructing an `undef` value to return in the error case, we were trying to get the element type of the Rust-level value being indexed instead of the underlying array; when indexing a slice, that's not an array and the LLVM assertion failure reflects this. The regression test is a lightly altered copy of `const-array-oob.rs`.
2 parents 80660d6 + fd07780 commit 59d27a7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
630630
// pass. Reporting here is a bit late.
631631
cx.sess().span_err(e.span,
632632
"const index-expr is out of bounds");
633-
C_undef(type_of::type_of(cx, bt).element_type())
633+
C_undef(val_ty(arr).element_type())
634634
} else {
635635
const_get_elt(cx, arr, &[iv as c_uint])
636636
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const FOO: &'static[u32] = &[1, 2, 3];
12+
const BAR: u32 = FOO[5]; //~ ERROR const index-expr is out of bounds
13+
14+
fn main() {
15+
let _ = BAR;
16+
}

0 commit comments

Comments
 (0)