1
1
#![ feature( plugin) ]
2
2
#![ warn( clippy:: indexing_slicing) ]
3
+ // We also check the out_of_bounds_indexing lint here, because it lints similar things and
4
+ // we want to avoid false positives.
3
5
#![ warn( clippy:: out_of_bounds_indexing) ]
4
6
#![ allow( clippy:: no_effect, clippy:: unnecessary_operation) ]
5
7
@@ -15,21 +17,10 @@ fn main() {
15
17
& x[ index_from..] [ ..index_to] ; // Two lint reports, one for [index_from..] and another for [..index_to].
16
18
x[ 4 ] ; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
17
19
x[ 1 << 3 ] ; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
18
- & x[ ..=4 ] ;
19
- & x[ 1 ..5 ] ;
20
- & x[ 5 ..] [ ..10 ] ; // Two lint reports, one for [5..] and another for [..10].
21
- & x[ 5 ..] ;
22
- & x[ ..5 ] ;
23
- & x[ 5 ..] . iter ( ) . map ( |x| 2 * x) . collect :: < Vec < i32 > > ( ) ;
24
- & x[ 0 ..=4 ] ;
20
+ & x[ 5 ..] [ ..10 ] ; // Two lint reports, one for out of bounds [5..] and another for slicing [..10].
25
21
& x[ 0 ..] [ ..3 ] ;
26
22
& x[ 1 ..] [ ..5 ] ;
27
23
28
- & x[ 4 ..] ; // Ok, should not produce stderr.
29
- & x[ ..4 ] ; // Ok, should not produce stderr.
30
- & x[ ..] ; // Ok, should not produce stderr.
31
- & x[ 1 ..] ; // Ok, should not produce stderr.
32
- & x[ 2 ..] . iter ( ) . map ( |x| 2 * x) . collect :: < Vec < i32 > > ( ) ; // Ok, should not produce stderr.
33
24
& x[ 0 ..] . get ( ..3 ) ; // Ok, should not produce stderr.
34
25
x[ 0 ] ; // Ok, should not produce stderr.
35
26
x[ 3 ] ; // Ok, should not produce stderr.
@@ -43,21 +34,6 @@ fn main() {
43
34
44
35
& y[ ..] ; // Ok, should not produce stderr.
45
36
46
- let empty: [ i8 ; 0 ] = [ ] ;
47
- empty[ 0 ] ; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
48
- & empty[ 1 ..5 ] ;
49
- & empty[ 0 ..=4 ] ;
50
- & empty[ ..=4 ] ;
51
- & empty[ 1 ..] ;
52
- & empty[ ..4 ] ;
53
- & empty[ 0 ..=0 ] ;
54
- & empty[ ..=0 ] ;
55
-
56
- & empty[ 0 ..] ; // Ok, should not produce stderr.
57
- & empty[ 0 ..0 ] ; // Ok, should not produce stderr.
58
- & empty[ ..0 ] ; // Ok, should not produce stderr.
59
- & empty[ ..] ; // Ok, should not produce stderr.
60
-
61
37
let v = vec ! [ 0 ; 5 ] ;
62
38
v[ 0 ] ;
63
39
v[ 10 ] ;
@@ -79,9 +55,4 @@ fn main() {
79
55
x[ M ] ; // Ok, should not produce stderr.
80
56
v[ N ] ;
81
57
v[ M ] ;
82
-
83
- // issue 3102
84
- let num = 1 ;
85
- & x[ num..10 ] ; // should trigger out of bounds error
86
- & x[ 10 ..num] ; // should trigger out of bounds error
87
58
}
0 commit comments