From e63f5dfedbb004afc6e9ca303b12f1c8f8cbea0d Mon Sep 17 00:00:00 2001 From: Shea Newton Date: Fri, 15 Jun 2018 15:54:38 +0000 Subject: [PATCH] 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. --- tests/ui/indexing_slicing.rs | 11 +++++++++++ tests/ui/indexing_slicing.stderr | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/ui/indexing_slicing.rs b/tests/ui/indexing_slicing.rs index 16174afb106..301658415d6 100644 --- a/tests/ui/indexing_slicing.rs +++ b/tests/ui/indexing_slicing.rs @@ -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]; } diff --git a/tests/ui/indexing_slicing.stderr b/tests/ui/indexing_slicing.stderr index c9aefe0349a..2546d62bfc6 100644 --- a/tests/ui/indexing_slicing.stderr +++ b/tests/ui/indexing_slicing.stderr @@ -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