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
This commit is contained in:
bors 2024-02-12 19:08:14 +00:00
commit 7dfa6ced9b
2 changed files with 6 additions and 0 deletions

View file

@ -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()

View file

@ -0,0 +1,5 @@
#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)]
fn main() {
let arr: [i32; 5] = [0; 5];
arr[0xfffffe7ffffffffffffffffffffffff];
}