]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/negative-literal-index.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / suggestions / negative-literal-index.rs
1 // run-rustfix
2
3 use std::ops::Index;
4 struct X;
5 impl Index<i32> for X {
6     type Output = ();
7
8     fn index(&self, _: i32) -> &() {
9         &()
10     }
11 }
12
13 fn main() {
14     let x = vec![1, 2, 3];
15     x[-1]; //~ ERROR negative integers cannot be used to index on a
16     let x = [1, 2, 3];
17     x[-1]; //~ ERROR negative integers cannot be used to index on a
18     let x = &[1, 2, 3];
19     x[-1]; //~ ERROR negative integers cannot be used to index on a
20     let _ = x;
21     X[-1];
22 }