granite-rust/tests/ui/indexing_slicing.stderr
Shea Newton 4ec439bef0
Revisiting indexing_slicing test cases
This commit contains a few changes. In an attempt to clarify which test cases should and should not produce stderr it became clear that some cases were being handled incorrectly. In order to address these test cases, a minor re-factor was made to the linting logic itself.

The re-factor was driven by edge case handling including a need for additional match conditions for `ExprCall` (`&x[0..=4]`) and `ExprBinary` (`x[1 << 3]`). Rather than attempt to account for each potential `Expr*` the code was re-factored into simply "if ranged index" and an "otherwise" conditions.
2018-06-19 16:28:10 +00:00

273 lines
6.1 KiB
Text

error: indexing may panic.
--> $DIR/indexing_slicing.rs:11:5
|
11 | x[index];
| ^^^^^^^^
|
= note: `-D indexing-slicing` implied by `-D warnings`
= help: Consider using `.get(n)` or `.get_mut(n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:12:6
|
12 | &x[index..];
| ^^^^^^^^^^
|
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:13:6
|
13 | &x[..index];
| ^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:14:6
|
14 | &x[index_from..index_to];
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:15:6
|
15 | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:15:6
|
15 | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to].
| ^^^^^^^^^^^^^^^
|
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
error: const index is out of bounds
--> $DIR/indexing_slicing.rs:16:5
|
16 | x[4];
| ^^^^
|
= note: `-D out-of-bounds-indexing` implied by `-D warnings`
error: const index is out of bounds
--> $DIR/indexing_slicing.rs:17:5
|
17 | x[1 << 3];
| ^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:18:6
|
18 | &x[..=4];
| ^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:19:6
|
19 | &x[1..5];
| ^^^^^^^
error: slicing may panic.
--> $DIR/indexing_slicing.rs:20:6
|
20 | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10].
| ^^^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: range is out of bounds
--> $DIR/indexing_slicing.rs:20:6
|
20 | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10].
| ^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:21:6
|
21 | &x[5..];
| ^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:22:6
|
22 | &x[..5];
| ^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:23:6
|
23 | &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
| ^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:24:6
|
24 | &x[0..=4];
| ^^^^^^^^
error: slicing may panic.
--> $DIR/indexing_slicing.rs:25:6
|
25 | &x[0..][..3];
| ^^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:26:6
|
26 | &x[1..][..5];
| ^^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: indexing may panic.
--> $DIR/indexing_slicing.rs:39:5
|
39 | y[0];
| ^^^^
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:40:6
|
40 | &y[1..2];
| ^^^^^^^
|
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:41:6
|
41 | &y[0..=4];
| ^^^^^^^^
|
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:42:6
|
42 | &y[..=4];
| ^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: const index is out of bounds
--> $DIR/indexing_slicing.rs:47:5
|
47 | empty[0];
| ^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:48:6
|
48 | &empty[1..5];
| ^^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:49:6
|
49 | &empty[0..=4];
| ^^^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:50:6
|
50 | &empty[..=4];
| ^^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:51:6
|
51 | &empty[1..];
| ^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:52:6
|
52 | &empty[..4];
| ^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:53:6
|
53 | &empty[0..=0];
| ^^^^^^^^^^^^
error: range is out of bounds
--> $DIR/indexing_slicing.rs:54:6
|
54 | &empty[..=0];
| ^^^^^^^^^^^
error: indexing may panic.
--> $DIR/indexing_slicing.rs:62:5
|
62 | v[0];
| ^^^^
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic.
--> $DIR/indexing_slicing.rs:63:5
|
63 | v[10];
| ^^^^^
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
error: indexing may panic.
--> $DIR/indexing_slicing.rs:64:5
|
64 | v[1 << 3];
| ^^^^^^^^^
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:65:6
|
65 | &v[10..100];
| ^^^^^^^^^^
|
= help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:66:6
|
66 | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
| ^^^^^^^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: range is out of bounds
--> $DIR/indexing_slicing.rs:66:6
|
66 | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
| ^^^^^^^
error: slicing may panic.
--> $DIR/indexing_slicing.rs:67:6
|
67 | &v[10..];
| ^^^^^^^
|
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
error: slicing may panic.
--> $DIR/indexing_slicing.rs:68:6
|
68 | &v[..100];
| ^^^^^^^^
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
error: aborting due to 38 previous errors