]> git.lizzy.rs Git - rust.git/blob - tests/ui/indexing_slicing_index.rs
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
[rust.git] / 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];
19
20     let v = vec![0; 5];
21     v[0];
22     v[10];
23     v[1 << 3];
24
25     const N: usize = 15; // Out of bounds
26     const M: usize = 3; // In bounds
27     x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
28     x[M]; // Ok, should not produce stderr.
29     v[N];
30     v[M];
31 }