mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 00:53:31 +00:00
38d4ac7cea
Discussion previously happened in https://github.com/rust-lang/rust/pull/43498
309 lines
7.3 KiB
Text
309 lines
7.3 KiB
Text
error: index out of bounds: the len is 4 but the index is 4
|
|
--> $DIR/indexing_slicing.rs:16:5
|
|
|
|
|
LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
|
|
| ^^^^
|
|
|
|
|
= note: #[deny(const_err)] on by default
|
|
|
|
error: index out of bounds: the len is 4 but the index is 8
|
|
--> $DIR/indexing_slicing.rs:17:5
|
|
|
|
|
LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
|
|
| ^^^^^^^^^
|
|
|
|
error: index out of bounds: the len is 0 but the index is 0
|
|
--> $DIR/indexing_slicing.rs:47:5
|
|
|
|
|
LL | empty[0]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
|
|
| ^^^^^^^^
|
|
|
|
error: index out of bounds: the len is 4 but the index is 15
|
|
--> $DIR/indexing_slicing.rs:78:5
|
|
|
|
|
LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays.
|
|
| ^^^^
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:11:5
|
|
|
|
|
LL | x[index];
|
|
| ^^^^^^^^
|
|
|
|
|
= note: `-D clippy::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
|
|
|
|
|
LL | &x[index..];
|
|
| ^^^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:13:6
|
|
|
|
|
LL | &x[..index];
|
|
| ^^^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:14:6
|
|
|
|
|
LL | &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
|
|
|
|
|
LL | &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
|
|
|
|
|
LL | &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: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:18:11
|
|
|
|
|
LL | &x[..=4];
|
|
| ^
|
|
|
|
|
= note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:19:11
|
|
|
|
|
LL | &x[1..5];
|
|
| ^
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:20:6
|
|
|
|
|
LL | &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:8
|
|
|
|
|
LL | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10].
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:21:8
|
|
|
|
|
LL | &x[5..];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:22:10
|
|
|
|
|
LL | &x[..5];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:23:8
|
|
|
|
|
LL | &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:24:12
|
|
|
|
|
LL | &x[0..=4];
|
|
| ^
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:25:6
|
|
|
|
|
LL | &x[0..][..3];
|
|
| ^^^^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:26:6
|
|
|
|
|
LL | &x[1..][..5];
|
|
| ^^^^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:39:5
|
|
|
|
|
LL | y[0];
|
|
| ^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:40:6
|
|
|
|
|
LL | &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
|
|
|
|
|
LL | &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
|
|
|
|
|
LL | &y[..=4];
|
|
| ^^^^^^^
|
|
|
|
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:48:12
|
|
|
|
|
LL | &empty[1..5];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:49:16
|
|
|
|
|
LL | &empty[0..=4];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:50:15
|
|
|
|
|
LL | &empty[..=4];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:51:12
|
|
|
|
|
LL | &empty[1..];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:52:14
|
|
|
|
|
LL | &empty[..4];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:53:16
|
|
|
|
|
LL | &empty[0..=0];
|
|
| ^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:54:15
|
|
|
|
|
LL | &empty[..=0];
|
|
| ^
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:62:5
|
|
|
|
|
LL | v[0];
|
|
| ^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:63:5
|
|
|
|
|
LL | v[10];
|
|
| ^^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:64:5
|
|
|
|
|
LL | v[1 << 3];
|
|
| ^^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:65:6
|
|
|
|
|
LL | &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
|
|
|
|
|
LL | &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:8
|
|
|
|
|
LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
|
|
| ^^
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:67:6
|
|
|
|
|
LL | &v[10..];
|
|
| ^^^^^^^
|
|
|
|
|
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
|
|
|
error: slicing may panic.
|
|
--> $DIR/indexing_slicing.rs:68:6
|
|
|
|
|
LL | &v[..100];
|
|
| ^^^^^^^^
|
|
|
|
|
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:80:5
|
|
|
|
|
LL | v[N];
|
|
| ^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: indexing may panic.
|
|
--> $DIR/indexing_slicing.rs:81:5
|
|
|
|
|
LL | v[M];
|
|
| ^^^^
|
|
|
|
|
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:85:13
|
|
|
|
|
LL | &x[num..10]; // should trigger out of bounds error
|
|
| ^^
|
|
|
|
error: range is out of bounds
|
|
--> $DIR/indexing_slicing.rs:86:8
|
|
|
|
|
LL | &x[10..num]; // should trigger out of bounds error
|
|
| ^^
|
|
|
|
error: aborting due to 43 previous errors
|
|
|