rust/tests/ui/suggestions/negative-literal-index.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
470 B
Rust
Raw Normal View History

// 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];
}