]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/indexing_slicing_index.rs
Auto merge of #84620 - Dylan-DPC:rollup-wkv97im, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / indexing_slicing_index.rs
1 #![warn(clippy::indexing_slicing)]
2 // We also check the out_of_bounds_indexing lint here, because it lints similar things and
3 // we want to avoid false positives.
4 #![warn(clippy::out_of_bounds_indexing)]
5 #![allow(clippy::no_effect, clippy::unnecessary_operation)]
6
7 fn main() {
8     let x = [1, 2, 3, 4];
9     let index: usize = 1;
10     x[index];
11     x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
12     x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
13
14     x[0]; // Ok, should not produce stderr.
15     x[3]; // Ok, should not produce stderr.
16
17     let y = &x;
18     y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021
19     y[4]; // Ok, rustc will handle references too.
20
21     let v = vec![0; 5];
22     v[0];
23     v[10];
24     v[1 << 3];
25
26     const N: usize = 15; // Out of bounds
27     const M: usize = 3; // In bounds
28     x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
29     x[M]; // Ok, should not produce stderr.
30     v[N];
31     v[M];
32 }