mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
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:
commit
7dfa6ced9b
2 changed files with 6 additions and 0 deletions
|
@ -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 a new issue