about summary refs log tree commit diff
path: root/library/core/tests
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-10-20 17:18:08 -0700
committerJosh Stone <jistone@redhat.com>2020-10-20 17:18:08 -0700
commit9202fbdbdbd60adb62839c3230738274e30f15fc (patch)
tree6d3e5083973900ea887238e6b3e7ec6ebcc249ce /library/core/tests
parent9fd79a39044be777a39604856d0a276484d6480f (diff)
downloadrust-9202fbdbdbd60adb62839c3230738274e30f15fc.tar.gz
rust-9202fbdbdbd60adb62839c3230738274e30f15fc.zip
Check for exhaustion in SliceIndex for RangeInclusive
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/slice.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index ac5c9353ccb..9ccc5a08dcb 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -1341,6 +1341,14 @@ mod slice_index {
             message: "out of range";
         }
 
+        in mod rangeinclusive_len {
+            data: [0, 1, 2, 3, 4, 5];
+
+            good: data[0..=5] == [0, 1, 2, 3, 4, 5];
+            bad: data[0..=6];
+            message: "out of range";
+        }
+
         in mod range_len_len {
             data: [0, 1, 2, 3, 4, 5];
 
@@ -1359,6 +1367,28 @@ mod slice_index {
     }
 
     panic_cases! {
+        in mod rangeinclusive_exhausted {
+            data: [0, 1, 2, 3, 4, 5];
+
+            good: data[0..=5] == [0, 1, 2, 3, 4, 5];
+            good: data[{
+                let mut iter = 0..=5;
+                iter.by_ref().count(); // exhaust it
+                iter
+            }] == [];
+
+            // 0..=6 is out of range before exhaustion, so it
+            // stands to reason that it still would be after.
+            bad: data[{
+                let mut iter = 0..=6;
+                iter.by_ref().count(); // exhaust it
+                iter
+            }];
+            message: "out of range";
+        }
+    }
+
+    panic_cases! {
         in mod range_neg_width {
             data: [0, 1, 2, 3, 4, 5];