]> git.lizzy.rs Git - rust.git/blob - tests/ui/indexing_slicing.rs
This commit represents an attempt to address changes requested in the process of...
[rust.git] / tests / ui / indexing_slicing.rs
1 #![feature(plugin)]
2 #![warn(indexing_slicing)]
3 #![warn(out_of_bounds_indexing)]
4 #![allow(no_effect, unnecessary_operation)]
5
6 fn main() {
7     let x = [1, 2, 3, 4];
8     let index: usize = 1;
9     let index_from: usize = 2;
10     let index_to: usize = 3;
11     x[index];
12     &x[index_from..index_to];
13     &x[index_from..][..index_to];
14     &x[index..];
15     &x[..index];
16     x[0];
17     x[3];
18     x[4];
19     x[1 << 3];
20     &x[1..5];
21     &x[1..][..5];
22     &x[0..3];
23     &x[0..][..3];
24     &x[0..].get(..3); // Ok
25     &x[0..=4];
26     &x[..=4];
27     &x[..];
28     &x[1..];
29     &x[4..];
30     &x[5..];
31     &x[..4];
32     &x[..5];
33
34     let y = &x;
35     y[0];
36     &y[1..2];
37     &y[..];
38     &y[0..=4];
39     &y[..=4];
40
41     let empty: [i8; 0] = [];
42     empty[0];
43     &empty[1..5];
44     &empty[0..=4];
45     &empty[..=4];
46     &empty[..];
47     &empty[0..];
48     &empty[0..0];
49     &empty[0..=0];
50     &empty[..=0];
51     &empty[..0];
52     &empty[1..];
53     &empty[..4];
54
55     let v = vec![0; 5];
56     v[0];
57     v[10];
58     &v[10..100];
59     &v[10..];
60     &v[..100];
61 }