fix: ICE when array index exceeds usize

This commit is contained in:
granddaifuku 2024-02-11 03:51:26 +09:00
parent e67b7e02da
commit c4d11083d9
2 changed files with 6 additions and 0 deletions

View File

@ -174,6 +174,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// 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];
}