Skip to content

Commit 38adec8

Browse files
granddaifukuflip1995
authored andcommitted
fix: ICE when array index exceeds usize
1 parent 6eeb080 commit 38adec8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/tools/clippy/clippy_lints/src/indexing_slicing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
174174
// only `usize` index is legal in rust array index
175175
// leave other type to rustc
176176
if let Constant::Int(off) = constant
177+
&& off <= usize::MAX as u128
177178
&& let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind()
178179
&& *utype == ty::UintTy::Usize
179180
&& let ty::Array(_, s) = ty.kind()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)]
2+
fn main() {
3+
let arr: [i32; 5] = [0; 5];
4+
arr[0xfffffe7ffffffffffffffffffffffff];
5+
}

0 commit comments

Comments
 (0)