Skip to content

Commit 11c16db

Browse files
committed
Fix ICE on using result of index on a constant to index into a constant
The issue was that the const evaluator was returning an error because the feature flag const_indexing wasn't turned on. The error was then reported as a bug. Fixes #29914
1 parent 5253294 commit 11c16db

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/librustc_trans/trans/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
663663
let iv = match eval_const_expr_partial(cx.tcx(), &index, ExprTypeChecked, None) {
664664
Ok(ConstVal::Int(i)) => i as u64,
665665
Ok(ConstVal::Uint(u)) => u,
666+
Err(e) => return Err(ConstEvalFailure::Compiletime(e)),
666667
_ => cx.sess().span_bug(index.span,
667668
"index is not an integer-constant expression")
668669
};

src/test/run-pass/issue-29914-2.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
#![feature(const_indexing)]
11+
12+
const ARR: [usize; 5] = [5, 4, 3, 2, 1];
13+
14+
fn main() {
15+
assert_eq!(3, ARR[ARR[3]]);
16+
}

src/test/run-pass/issue-29914.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 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 ARR: [usize; 5] = [5, 4, 3, 2, 1];
12+
13+
fn main() {
14+
assert_eq!(3, ARR[ARR[3]]);
15+
}

0 commit comments

Comments
 (0)