Skip to content

Commit 33cc140

Browse files
committed
add more negative tests
1 parent 11072b5 commit 33cc140

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/ui/iter_out_of_bounds.rs

+10
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ fn main() {
5757

5858
for _ in std::iter::once(1).take(2) {}
5959
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
60+
61+
for x in [].iter().take(1) {
62+
//~^ ERROR: this `.take()` call takes more items than the iterator will produce
63+
let _: &i32 = x;
64+
}
65+
66+
// ok, not out of bounds
67+
for _ in [1].iter().take(1) {}
68+
for _ in [1, 2, 3].iter().take(2) {}
69+
for _ in [1, 2, 3].iter().skip(2) {}
6070
}

tests/ui/iter_out_of_bounds.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,13 @@ LL | for _ in std::iter::once(1).take(2) {}
107107
|
108108
= note: this operation is useless and the returned iterator will simply yield the same items
109109

110-
error: aborting due to 13 previous errors
110+
error: this `.take()` call takes more items than the iterator will produce
111+
--> $DIR/iter_out_of_bounds.rs:61:14
112+
|
113+
LL | for x in [].iter().take(1) {
114+
| ^^^^^^^^^^^^^^^^^
115+
|
116+
= note: this operation is useless and the returned iterator will simply yield the same items
117+
118+
error: aborting due to 14 previous errors
111119

0 commit comments

Comments
 (0)