]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/array_indexing.rs
35fadf8c1e4add72b5dc751f12004cc5a925c1af
[rust.git] / tests / compile-fail / array_indexing.rs
1 #![feature(inclusive_range_syntax, plugin)]
2 #![plugin(clippy)]
3
4 #![deny(indexing_slicing)]
5 #![deny(out_of_bounds_indexing)]
6 #![allow(no_effect)]
7
8 fn main() {
9     let x = [1,2,3,4];
10     x[0];
11     x[3];
12     x[4]; //~ERROR: const index is out of bounds
13     x[1 << 3]; //~ERROR: const index is out of bounds
14     &x[1..5]; //~ERROR: range is out of bounds
15     &x[0..3];
16     &x[0...4]; //~ERROR: range is out of bounds
17     &x[..];
18     &x[1..];
19     &x[4..];
20     &x[5..]; //~ERROR: range is out of bounds
21     &x[..4];
22     &x[..5]; //~ERROR: range is out of bounds
23
24     let y = &x;
25     y[0]; //~ERROR: indexing may panic
26     &y[1..2]; //~ERROR: slicing may panic
27     &y[..];
28     &y[0...4]; //~ERROR: slicing may panic
29
30     let empty: [i8; 0] = [];
31     empty[0]; //~ERROR: const index is out of bounds
32     &empty[1..5]; //~ERROR: range is out of bounds
33     &empty[0...4]; //~ERROR: range is out of bounds
34     &empty[..];
35     &empty[0..];
36     &empty[0..0];
37     &empty[0...0]; //~ERROR: range is out of bounds
38     &empty[..0];
39     &empty[1..]; //~ERROR: range is out of bounds
40     &empty[..4]; //~ERROR: range is out of bounds
41 }