Skip to content

Commit

Permalink
Auto merge of #30714 - wesleywiser:fix_29914, r=arielb1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 6, 2016
2 parents 5daa753 + 11c16db commit 1f86f80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_trans/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let iv = match eval_const_expr_partial(cx.tcx(), &index, ExprTypeChecked, None) {
Ok(ConstVal::Int(i)) => i as u64,
Ok(ConstVal::Uint(u)) => u,
Err(e) => return Err(ConstEvalFailure::Compiletime(e)),
_ => cx.sess().span_bug(index.span,
"index is not an integer-constant expression")
};
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-29914-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_indexing)]

const ARR: [usize; 5] = [5, 4, 3, 2, 1];

fn main() {
assert_eq!(3, ARR[ARR[3]]);
}
15 changes: 15 additions & 0 deletions src/test/run-pass/issue-29914.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

const ARR: [usize; 5] = [5, 4, 3, 2, 1];

fn main() {
assert_eq!(3, ARR[ARR[3]]);
}

0 comments on commit 1f86f80

Please sign in to comment.