mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
fix: ICE when array index exceeds usize
This commit is contained in:
parent
e67b7e02da
commit
c4d11083d9
@ -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()
|
||||
|
5
tests/ui/crashes/ice-12253.rs
Normal file
5
tests/ui/crashes/ice-12253.rs
Normal file
@ -0,0 +1,5 @@
|
||||
#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)]
|
||||
fn main() {
|
||||
let arr: [i32; 5] = [0; 5];
|
||||
arr[0xfffffe7ffffffffffffffffffffffff];
|
||||
}
|
Loading…
Reference in New Issue
Block a user