about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-12 19:08:14 +0000
committerbors <bors@rust-lang.org>2024-02-12 19:08:14 +0000
commit7dfa6ced9b826bdb2494f91df2060d527dab4dff (patch)
treeaabf54c9c5462bb6c843b08cd8162533a18d3f8a
parentb0e7640fd7b2f8b40da520bc25848e7d6a0441e4 (diff)
parentc4d11083d9ee8efb873cff069b0282be68a37ab2 (diff)
downloadrust-7dfa6ced9b826bdb2494f91df2060d527dab4dff.tar.gz
rust-7dfa6ced9b826bdb2494f91df2060d527dab4dff.zip
Auto merge of #12266 - granddaifuku:fix/ice-12253-index-exceeds-usize, r=Manishearth
fix: ICE when array index exceeds usize

fixes #12253

This PR fixes ICE in `indexing_slicing` as it panics when the index of the array exceeds `usize`.

changelog: none
-rw-r--r--clippy_lints/src/indexing_slicing.rs1
-rw-r--r--tests/ui/crashes/ice-12253.rs5
2 files changed, 6 insertions, 0 deletions
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];
+}