]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/indexing_slicing_slice.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / indexing_slicing_slice.rs
CommitLineData
f20569fa
XL
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)]
fe692bf9 5#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec)]
f20569fa
XL
6
7fn main() {
8 let x = [1, 2, 3, 4];
9 let index: usize = 1;
10 let index_from: usize = 2;
11 let index_to: usize = 3;
12 &x[index..];
13 &x[..index];
14 &x[index_from..index_to];
15 &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
16 &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10].
17 &x[0..][..3];
18 &x[1..][..5];
19
20 &x[0..].get(..3); // Ok, should not produce stderr.
21 &x[0..3]; // Ok, should not produce stderr.
22
23 let y = &x;
24 &y[1..2];
25 &y[0..=4];
26 &y[..=4];
27
28 &y[..]; // Ok, should not produce stderr.
29
30 let v = vec![0; 5];
31 &v[10..100];
32 &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
33 &v[10..];
34 &v[..100];
35
36 &v[..]; // Ok, should not produce stderr.
37}