diff options
| author | bors <bors@rust-lang.org> | 2020-04-20 23:54:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-20 23:54:15 +0000 |
| commit | b3cb9b8376b79837ec525da017871ab1859292dc (patch) | |
| tree | 951b43fdbb17a23216cdc0667d6bcf795d6d3e59 | |
| parent | 6507728f231b00cabd8b3957ac642dbcc854abb1 (diff) | |
| parent | 7221db2dc34f93f42cd4b5d5fefa573acf247668 (diff) | |
| download | rust-b3cb9b8376b79837ec525da017871ab1859292dc.tar.gz rust-b3cb9b8376b79837ec525da017871ab1859292dc.zip | |
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
| -rw-r--r-- | clippy_lints/src/consts.rs | 6 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-5497.rs | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b9160712915..7916996e990 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -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)), _) => { diff --git a/tests/ui/crashes/ice-5497.rs b/tests/ui/crashes/ice-5497.rs new file mode 100644 index 00000000000..0769bce5fc8 --- /dev/null +++ b/tests/ui/crashes/ice-5497.rs @@ -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 +} |
