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
This commit is contained in:
parent
bc9192738d
commit
271777ce22
4 changed files with 53 additions and 8 deletions
|
@ -24,8 +24,6 @@ use middle::const_eval::{const_int_checked_div, const_uint_checked_div};
|
||||||
use middle::const_eval::{const_int_checked_rem, const_uint_checked_rem};
|
use middle::const_eval::{const_int_checked_rem, const_uint_checked_rem};
|
||||||
use middle::const_eval::{const_int_checked_shl, const_uint_checked_shl};
|
use middle::const_eval::{const_int_checked_shl, const_uint_checked_shl};
|
||||||
use middle::const_eval::{const_int_checked_shr, const_uint_checked_shr};
|
use middle::const_eval::{const_int_checked_shr, const_uint_checked_shr};
|
||||||
use middle::const_eval::EvalHint::ExprTypeChecked;
|
|
||||||
use middle::const_eval::eval_const_expr_partial;
|
|
||||||
use middle::def::Def;
|
use middle::def::Def;
|
||||||
use middle::def_id::DefId;
|
use middle::def_id::DefId;
|
||||||
use trans::{adt, closure, debuginfo, expr, inline, machine};
|
use trans::{adt, closure, debuginfo, expr, inline, machine};
|
||||||
|
@ -261,7 +259,7 @@ impl ConstEvalFailure {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum TrueConst {
|
pub enum TrueConst {
|
||||||
Yes, No
|
Yes, No
|
||||||
}
|
}
|
||||||
|
@ -665,11 +663,11 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||||
},
|
},
|
||||||
hir::ExprIndex(ref base, ref index) => {
|
hir::ExprIndex(ref base, ref index) => {
|
||||||
let (bv, bt) = try!(const_expr(cx, &base, param_substs, fn_args, trueconst));
|
let (bv, bt) = try!(const_expr(cx, &base, param_substs, fn_args, trueconst));
|
||||||
let iv = match eval_const_expr_partial(cx.tcx(), &index, ExprTypeChecked, None) {
|
let iv = try!(const_expr(cx, &index, param_substs, fn_args, TrueConst::Yes)).0;
|
||||||
Ok(ConstVal::Int(i)) => i as u64,
|
let iv = if let Some(iv) = const_to_opt_uint(iv) {
|
||||||
Ok(ConstVal::Uint(u)) => u,
|
iv
|
||||||
_ => cx.sess().span_bug(index.span,
|
} else {
|
||||||
"index is not an integer-constant expression")
|
cx.sess().span_bug(index.span, "index is not an integer-constant expression");
|
||||||
};
|
};
|
||||||
let (arr, len) = match bt.sty {
|
let (arr, len) = match bt.sty {
|
||||||
ty::TyArray(_, u) => (bv, C_uint(cx, u)),
|
ty::TyArray(_, u) => (bv, C_uint(cx, u)),
|
||||||
|
|
15
src/test/run-pass/issue-29914-2.rs
Normal file
15
src/test/run-pass/issue-29914-2.rs
Normal file
|
@ -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]]);
|
||||||
|
}
|
16
src/test/run-pass/issue-29914-3.rs
Normal file
16
src/test/run-pass/issue-29914-3.rs
Normal file
|
@ -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.
|
||||||
|
|
||||||
|
const ARR: [usize; 5] = [5, 4, 3, 2, 1];
|
||||||
|
const BLA: usize = ARR[ARR[3]];
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(3, BLA);
|
||||||
|
}
|
16
src/test/run-pass/issue-29914.rs
Normal file
16
src/test/run-pass/issue-29914.rs
Normal file
|
@ -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]]);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue