mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Add tests that index with a const
value.
In this commit tests were added to ensure that tests with a `const` index behaved as expected. In order to minimize the changes to the test's corresponding `stderr`, the tests were appended to the end of the file.
This commit is contained in:
parent
4ec439bef0
commit
e63f5dfedb
2 changed files with 34 additions and 1 deletions
|
@ -68,4 +68,15 @@ fn main() {
|
|||
&v[..100];
|
||||
|
||||
&v[..]; // Ok, should not produce stderr.
|
||||
|
||||
//
|
||||
// Continue tests at end function to minimize the changes to this file's corresponding stderr.
|
||||
//
|
||||
|
||||
const N: usize = 15; // Out of bounds
|
||||
const M: usize = 3; // In bounds
|
||||
x[N];
|
||||
x[M]; // Ok, should not produce stderr.
|
||||
v[N];
|
||||
v[M];
|
||||
}
|
||||
|
|
|
@ -269,5 +269,27 @@ error: slicing may panic.
|
|||
|
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: aborting due to 38 previous errors
|
||||
error: const index is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:78:5
|
||||
|
|
||||
78 | x[N];
|
||||
| ^^^^
|
||||
|
||||
error: indexing may panic.
|
||||
--> $DIR/indexing_slicing.rs:80:5
|
||||
|
|
||||
80 | v[N];
|
||||
| ^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: indexing may panic.
|
||||
--> $DIR/indexing_slicing.rs:81:5
|
||||
|
|
||||
81 | v[M];
|
||||
| ^^^^
|
||||
|
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: aborting due to 41 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue