Skip to content

Commit e63f5df

Browse files
committed
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.
1 parent 4ec439b commit e63f5df

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/ui/indexing_slicing.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,15 @@ fn main() {
6868
&v[..100];
6969

7070
&v[..]; // Ok, should not produce stderr.
71+
72+
//
73+
// Continue tests at end function to minimize the changes to this file's corresponding stderr.
74+
//
75+
76+
const N: usize = 15; // Out of bounds
77+
const M: usize = 3; // In bounds
78+
x[N];
79+
x[M]; // Ok, should not produce stderr.
80+
v[N];
81+
v[M];
7182
}

tests/ui/indexing_slicing.stderr

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,27 @@ error: slicing may panic.
269269
|
270270
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
271271

272-
error: aborting due to 38 previous errors
272+
error: const index is out of bounds
273+
--> $DIR/indexing_slicing.rs:78:5
274+
|
275+
78 | x[N];
276+
| ^^^^
277+
278+
error: indexing may panic.
279+
--> $DIR/indexing_slicing.rs:80:5
280+
|
281+
80 | v[N];
282+
| ^^^^
283+
|
284+
= help: Consider using `.get(n)` or `.get_mut(n)` instead
285+
286+
error: indexing may panic.
287+
--> $DIR/indexing_slicing.rs:81:5
288+
|
289+
81 | v[M];
290+
| ^^^^
291+
|
292+
= help: Consider using `.get(n)` or `.get_mut(n)` instead
293+
294+
error: aborting due to 41 previous errors
273295

0 commit comments

Comments
 (0)