summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/negative-literal-index.rs
blob: d88b66e679e56d2fd6df33fdad7ab07310bf9be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// run-rustfix

use std::ops::Index;
struct X;
impl Index<i32> for X {
    type Output = ();

    fn index(&self, _: i32) -> &() {
        &()
    }
}

fn main() {
    let x = vec![1, 2, 3];
    x[-1]; //~ ERROR negative integers cannot be used to index on a
    let x = [1, 2, 3];
    x[-1]; //~ ERROR negative integers cannot be used to index on a
    let x = &[1, 2, 3];
    x[-1]; //~ ERROR negative integers cannot be used to index on a
    let _ = x;
    X[-1];
}