From c4d11083d9ee8efb873cff069b0282be68a37ab2 Mon Sep 17 00:00:00 2001 From: granddaifuku Date: Sun, 11 Feb 2024 03:51:26 +0900 Subject: [PATCH] fix: ICE when array index exceeds usize --- clippy_lints/src/indexing_slicing.rs | 1 + tests/ui/crashes/ice-12253.rs | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 tests/ui/crashes/ice-12253.rs diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 391db0b0df7..35fcd8cdd35 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -174,6 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { // only `usize` index is legal in rust array index // leave other type to rustc if let Constant::Int(off) = constant + && off <= usize::MAX as u128 && let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind() && *utype == ty::UintTy::Usize && let ty::Array(_, s) = ty.kind() diff --git a/tests/ui/crashes/ice-12253.rs b/tests/ui/crashes/ice-12253.rs new file mode 100644 index 00000000000..41f50035144 --- /dev/null +++ b/tests/ui/crashes/ice-12253.rs @@ -0,0 +1,5 @@ +#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)] +fn main() { + let arr: [i32; 5] = [0; 5]; + arr[0xfffffe7ffffffffffffffffffffffff]; +}