File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,14 @@ fn main() {
57
57
58
58
for _ in std:: iter:: once ( 1 ) . take ( 2 ) { }
59
59
//~^ 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 ) { }
60
70
}
Original file line number Diff line number Diff line change @@ -107,5 +107,13 @@ LL | for _ in std::iter::once(1).take(2) {}
107
107
|
108
108
= note: this operation is useless and the returned iterator will simply yield the same items
109
109
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
111
119
You can’t perform that action at this time.
0 commit comments