1 #![feature(tool_lints)]
4 #![warn(clippy::indexing_slicing)]
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.
22 &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10].
25 &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
30 &x[4..]; // Ok, should not produce stderr.
31 &x[..4]; // Ok, should not produce stderr.
32 &x[..]; // Ok, should not produce stderr.
33 &x[1..]; // Ok, should not produce stderr.
34 &x[2..].iter().map(|x| 2 * x).collect::<Vec<i32>>(); // Ok, should not produce stderr.
35 &x[0..].get(..3); // Ok, should not produce stderr.
36 x[0]; // Ok, should not produce stderr.
37 x[3]; // Ok, should not produce stderr.
38 &x[0..3]; // Ok, should not produce stderr.
46 &y[..]; // Ok, should not produce stderr.
48 let empty: [i8; 0] = [];
49 empty[0]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
58 &empty[0..]; // Ok, should not produce stderr.
59 &empty[0..0]; // Ok, should not produce stderr.
60 &empty[..0]; // Ok, should not produce stderr.
61 &empty[..]; // Ok, should not produce stderr.
68 &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
72 &v[..]; // Ok, should not produce stderr.
75 // Continue tests at end function to minimize the changes to this file's corresponding stderr.
78 const N: usize = 15; // Out of bounds
79 const M: usize = 3; // In bounds
80 x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
81 x[M]; // Ok, should not produce stderr.