11#![ feature( plugin) ]
22#![ 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.
35#![ warn( clippy:: out_of_bounds_indexing) ]
46#![ allow( clippy:: no_effect, clippy:: unnecessary_operation) ]
57
@@ -15,21 +17,10 @@ fn main() {
1517 & x[ index_from..] [ ..index_to] ; // Two lint reports, one for [index_from..] and another for [..index_to].
1618 x[ 4 ] ; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
1719 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].
2521 & x[ 0 ..] [ ..3 ] ;
2622 & x[ 1 ..] [ ..5 ] ;
2723
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.
3324 & x[ 0 ..] . get ( ..3 ) ; // Ok, should not produce stderr.
3425 x[ 0 ] ; // Ok, should not produce stderr.
3526 x[ 3 ] ; // Ok, should not produce stderr.
@@ -43,21 +34,6 @@ fn main() {
4334
4435 & y[ ..] ; // Ok, should not produce stderr.
4536
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-
6137 let v = vec ! [ 0 ; 5 ] ;
6238 v[ 0 ] ;
6339 v[ 10 ] ;
@@ -79,9 +55,4 @@ fn main() {
7955 x[ M ] ; // Ok, should not produce stderr.
8056 v[ N ] ;
8157 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
8758}
0 commit comments