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:
Shea Newton 2018-06-15 15:54:38 +00:00
parent 4ec439bef0
commit e63f5dfedb
No known key found for this signature in database
GPG key ID: 17EB9122DC958643
2 changed files with 34 additions and 1 deletions

View file

@ -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];
}

View file

@ -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