File tree 2 files changed +65
-0
lines changed
tests/ui/out_of_bounds_indexing
2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ warn( clippy:: out_of_bounds_indexing) ]
2
+ #![ allow( clippy:: no_effect, clippy:: unnecessary_operation, const_err) ]
3
+
4
+ fn main ( ) {
5
+ let empty: [ i8 ; 0 ] = [ ] ;
6
+ empty[ 0 ] ;
7
+ & empty[ 1 ..5 ] ;
8
+ & empty[ 0 ..=4 ] ;
9
+ & empty[ ..=4 ] ;
10
+ & empty[ 1 ..] ;
11
+ & empty[ ..4 ] ;
12
+ & empty[ 0 ..=0 ] ;
13
+ & empty[ ..=0 ] ;
14
+
15
+ & empty[ 0 ..] ; // Ok, should not produce stderr.
16
+ & empty[ 0 ..0 ] ; // Ok, should not produce stderr.
17
+ & empty[ ..0 ] ; // Ok, should not produce stderr.
18
+ & empty[ ..] ; // Ok, should not produce stderr.
19
+ }
Original file line number Diff line number Diff line change
1
+ error: range is out of bounds
2
+ --> $DIR/empty_array.rs:7:12
3
+ |
4
+ LL | &empty[1..5];
5
+ | ^
6
+ |
7
+ = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
8
+
9
+ error: range is out of bounds
10
+ --> $DIR/empty_array.rs:8:16
11
+ |
12
+ LL | &empty[0..=4];
13
+ | ^
14
+
15
+ error: range is out of bounds
16
+ --> $DIR/empty_array.rs:9:15
17
+ |
18
+ LL | &empty[..=4];
19
+ | ^
20
+
21
+ error: range is out of bounds
22
+ --> $DIR/empty_array.rs:10:12
23
+ |
24
+ LL | &empty[1..];
25
+ | ^
26
+
27
+ error: range is out of bounds
28
+ --> $DIR/empty_array.rs:11:14
29
+ |
30
+ LL | &empty[..4];
31
+ | ^
32
+
33
+ error: range is out of bounds
34
+ --> $DIR/empty_array.rs:12:16
35
+ |
36
+ LL | &empty[0..=0];
37
+ | ^
38
+
39
+ error: range is out of bounds
40
+ --> $DIR/empty_array.rs:13:15
41
+ |
42
+ LL | &empty[..=0];
43
+ | ^
44
+
45
+ error: aborting due to 7 previous errors
46
+
You can’t perform that action at this time.
0 commit comments