Skip to content

Commit

Permalink
Auto merge of #5499 - matthiaskrgr:crash_5497, r=flip1995
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 20, 2020
2 parents 6507728 + 7221db2 commit b3cb9b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)), _) => {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/crashes/ice-5497.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b3cb9b8

Please sign in to comment.