Skip to content

Commit b3cb9b8

Browse files
committed
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
2 parents 6507728 + 7221db2 commit b3cb9b8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clippy_lints/src/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
351351
let index = self.expr(index);
352352

353353
match (lhs, index) {
354-
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec[index as usize] {
355-
Constant::F32(x) => Some(Constant::F32(x)),
356-
Constant::F64(x) => Some(Constant::F64(x)),
354+
(Some(Constant::Vec(vec)), Some(Constant::Int(index))) => match vec.get(index as usize) {
355+
Some(Constant::F32(x)) => Some(Constant::F32(*x)),
356+
Some(Constant::F64(x)) => Some(Constant::F64(*x)),
357357
_ => None,
358358
},
359359
(Some(Constant::Vec(vec)), _) => {

tests/ui/crashes/ice-5497.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// reduced from rustc issue-69020-assoc-const-arith-overflow.rs
2+
pub fn main() {}
3+
4+
pub trait Foo {
5+
const OOB: i32;
6+
}
7+
8+
impl<T: Foo> Foo for Vec<T> {
9+
const OOB: i32 = [1][1] + T::OOB;
10+
//~^ ERROR operation will panic
11+
}

0 commit comments

Comments
 (0)