Skip to content

Commit 33010ae

Browse files
committed
UI Test Cleanup: Split out out_of_bounds_indexing
This moves the `out_of_bounds_indexing` lint tests to their own directory.
1 parent a73bb33 commit 33010ae

File tree

8 files changed

+209
-158
lines changed

8 files changed

+209
-158
lines changed

tests/ui/indexing_slicing.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![feature(plugin)]
22
#![warn(clippy::indexing_slicing)]
3+
4+
// We also check the out_of_bounds_indexing lint here, because it lints similar things and
5+
// we want to avoid false positives.
36
#![warn(clippy::out_of_bounds_indexing)]
47
#![allow(clippy::no_effect, clippy::unnecessary_operation)]
58

@@ -15,21 +18,10 @@ fn main() {
1518
&x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
1619
x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
1720
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];
21+
&x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10].
2522
&x[0..][..3];
2623
&x[1..][..5];
2724

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.
3325
&x[0..].get(..3); // Ok, should not produce stderr.
3426
x[0]; // Ok, should not produce stderr.
3527
x[3]; // Ok, should not produce stderr.
@@ -43,21 +35,6 @@ fn main() {
4335

4436
&y[..]; // Ok, should not produce stderr.
4537

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-
6138
let v = vec![0; 5];
6239
v[0];
6340
v[10];
@@ -79,9 +56,4 @@ fn main() {
7956
x[M]; // Ok, should not produce stderr.
8057
v[N];
8158
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
8759
}

0 commit comments

Comments
 (0)