1 #![feature(inline_const)]
2 #![warn(clippy::indexing_slicing)]
3 // We also check the out_of_bounds_indexing lint here, because it lints similar things and
4 // we want to avoid false positives.
5 #![warn(clippy::out_of_bounds_indexing)]
6 #![allow(unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)]
8 const ARR: [i32; 2] = [1, 2];
9 const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr.
10 const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
12 const fn idx() -> usize {
15 const fn idx4() -> usize {
23 x[4]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
24 x[1 << 3]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
26 x[0]; // Ok, should not produce stderr.
27 x[3]; // Ok, should not produce stderr.
28 x[const { idx() }]; // Ok, should not produce stderr.
29 x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
30 const { &ARR[idx()] }; // Ok, should not produce stderr.
31 const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
34 y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021
35 y[4]; // Ok, rustc will handle references too.
42 const N: usize = 15; // Out of bounds
43 const M: usize = 3; // In bounds
44 x[N]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
45 x[M]; // Ok, should not produce stderr.