-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #5130 - JohnTitor:split-up-index-slice, r=flip1995
Split up `indexing_slicing` ui test Closes #2038 Now all the stderrs are less than 200 lines 🎉 changelog: none
- Loading branch information
Showing
5 changed files
with
130 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![warn(clippy::indexing_slicing)] | ||
// We also check the out_of_bounds_indexing lint here, because it lints similar things and | ||
// we want to avoid false positives. | ||
#![warn(clippy::out_of_bounds_indexing)] | ||
#![allow(clippy::no_effect, clippy::unnecessary_operation)] | ||
|
||
fn main() { | ||
let x = [1, 2, 3, 4]; | ||
let index: usize = 1; | ||
x[index]; | ||
x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ||
x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ||
|
||
x[0]; // Ok, should not produce stderr. | ||
x[3]; // Ok, should not produce stderr. | ||
|
||
let y = &x; | ||
y[0]; | ||
|
||
let v = vec![0; 5]; | ||
v[0]; | ||
v[10]; | ||
v[1 << 3]; | ||
|
||
const N: usize = 15; // Out of bounds | ||
const M: usize = 3; // In bounds | ||
x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ||
x[M]; // Ok, should not produce stderr. | ||
v[N]; | ||
v[M]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
error: index out of bounds: the len is 4 but the index is 4 | ||
--> $DIR/indexing_slicing_index.rs:11: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_index.rs:12: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 4 but the index is 15 | ||
--> $DIR/indexing_slicing_index.rs:27:5 | ||
| | ||
LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ||
| ^^^^ | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:10:5 | ||
| | ||
LL | x[index]; | ||
| ^^^^^^^^ | ||
| | ||
= note: `-D clippy::indexing-slicing` implied by `-D warnings` | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:18:5 | ||
| | ||
LL | y[0]; | ||
| ^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:21:5 | ||
| | ||
LL | v[0]; | ||
| ^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:22:5 | ||
| | ||
LL | v[10]; | ||
| ^^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:23:5 | ||
| | ||
LL | v[1 << 3]; | ||
| ^^^^^^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:29:5 | ||
| | ||
LL | v[N]; | ||
| ^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: indexing may panic. | ||
--> $DIR/indexing_slicing_index.rs:30:5 | ||
| | ||
LL | v[M]; | ||
| ^^^^ | ||
| | ||
= help: Consider using `.get(n)` or `.get_mut(n)` instead | ||
|
||
error: aborting due to 10 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.