about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
blob: e613e527eee48b361f5215e150bd7eef6cfbe6ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![warn(clippy::out_of_bounds_indexing)]
#![allow(clippy::no_effect, clippy::unnecessary_operation)]

fn main() {
    let x = [1, 2, 3, 4];

    &x[..=4];
    //~^ out_of_bounds_indexing

    &x[1..5];
    //~^ out_of_bounds_indexing

    &x[5..];
    //~^ out_of_bounds_indexing

    &x[..5];
    //~^ out_of_bounds_indexing

    &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
    //~^ out_of_bounds_indexing

    &x[0..=4];
    //~^ out_of_bounds_indexing

    &x[4..]; // Ok, should not produce stderr.
    &x[..4]; // Ok, should not produce stderr.
    &x[..]; // Ok, should not produce stderr.
    &x[1..]; // Ok, should not produce stderr.
    &x[2..].iter().map(|x| 2 * x).collect::<Vec<i32>>(); // Ok, should not produce stderr.

    &x[0..].get(..3); // Ok, should not produce stderr.
    &x[0..3]; // Ok, should not produce stderr.
}