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 Foo for Vec { + const OOB: i32 = [1][1] + T::OOB; + //~^ ERROR operation will panic +}