Auto merge of #5499 - matthiaskrgr:crash_5497, r=flip1995

fix crash on issue-69020-assoc-const-arith-overflow.rs

Fixes #5497

changelog: fix crash on rustc test issue-69020-assoc-const-arith-overflow.rs
This commit is contained in:
bors 2020-04-20 23:54:15 +00:00
commit b3cb9b8376
2 changed files with 14 additions and 3 deletions

View File

@ -351,9 +351,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
let index = self.expr(index);
match (lhs, index) {
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec[index as usize] {
Constant::F32(x) => Some(Constant::F32(x)),
Constant::F64(x) => Some(Constant::F64(x)),
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) {
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
_ => None,
},
(Some(Constant::Vec(vec)), _) => {

View File

@ -0,0 +1,11 @@
// reduced from rustc issue-69020-assoc-const-arith-overflow.rs
pub fn main() {}
pub trait Foo {
const OOB: i32;
}
impl<T: Foo> Foo for Vec<T> {
const OOB: i32 = [1][1] + T::OOB;
//~^ ERROR operation will panic
}