summaryrefslogtreecommitdiffstats
path: root/src/test/ui/suggestions/negative-literal-index.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/suggestions/negative-literal-index.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/negative-literal-index.rs b/src/test/ui/suggestions/negative-literal-index.rs
new file mode 100644
index 000000000..d88b66e67
--- /dev/null
+++ b/src/test/ui/suggestions/negative-literal-index.rs
@@ -0,0 +1,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];
+}