about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-08-27 23:38:43 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-08-27 23:38:43 +0200
commit33cc140f55e254c7c88e81b059afcc430bba3e5e (patch)
tree62c2c4ad32d30ace1d16661594787dcd5dc37d83
parent11072b51fa2b8fbcf68f8cf6a5f4140b19c16241 (diff)
downloadrust-33cc140f55e254c7c88e81b059afcc430bba3e5e.tar.gz
rust-33cc140f55e254c7c88e81b059afcc430bba3e5e.zip
add more negative tests
-rw-r--r--tests/ui/iter_out_of_bounds.rs10
-rw-r--r--tests/ui/iter_out_of_bounds.stderr10
2 files changed, 19 insertions, 1 deletions
diff --git a/tests/ui/iter_out_of_bounds.rs b/tests/ui/iter_out_of_bounds.rs
index a2c17b452d6..c34eb1be0c5 100644
--- a/tests/ui/iter_out_of_bounds.rs
+++ b/tests/ui/iter_out_of_bounds.rs
@@ -57,4 +57,14 @@ fn main() {
 
     for _ in std::iter::once(1).take(2) {}
     //~^ ERROR: this `.take()` call takes more items than the iterator will produce
+
+    for x in [].iter().take(1) {
+        //~^ ERROR: this `.take()` call takes more items than the iterator will produce
+        let _: &i32 = x;
+    }
+
+    // ok, not out of bounds
+    for _ in [1].iter().take(1) {}
+    for _ in [1, 2, 3].iter().take(2) {}
+    for _ in [1, 2, 3].iter().skip(2) {}
 }
diff --git a/tests/ui/iter_out_of_bounds.stderr b/tests/ui/iter_out_of_bounds.stderr
index d4b7b4355d0..98ee28fcaf6 100644
--- a/tests/ui/iter_out_of_bounds.stderr
+++ b/tests/ui/iter_out_of_bounds.stderr
@@ -107,5 +107,13 @@ LL |     for _ in std::iter::once(1).take(2) {}
    |
    = note: this operation is useless and the returned iterator will simply yield the same items
 
-error: aborting due to 13 previous errors
+error: this `.take()` call takes more items than the iterator will produce
+  --> $DIR/iter_out_of_bounds.rs:61:14
+   |
+LL |     for x in [].iter().take(1) {
+   |              ^^^^^^^^^^^^^^^^^
+   |
+   = note: this operation is useless and the returned iterator will simply yield the same items
+
+error: aborting due to 14 previous errors