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(clippy::no_effect, clippy::unnecessary_operation)]
11 let index_from: usize = 2;
12 let index_to: usize = 3;
16 &x[index_from..index_to];
17 &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
18 x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
19 x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
20 &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10].
24 &x[0..].get(..3); // Ok, should not produce stderr.
25 x[0]; // Ok, should not produce stderr.
26 x[3]; // Ok, should not produce stderr.
27 &x[0..3]; // Ok, should not produce stderr.
35 &y[..]; // Ok, should not produce stderr.
42 &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
46 &v[..]; // Ok, should not produce stderr.
49 // Continue tests at end function to minimize the changes to this file's corresponding stderr.
52 const N: usize = 15; // Out of bounds
53 const M: usize = 3; // In bounds
54 x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
55 x[M]; // Ok, should not produce stderr.