Skip to content

Commit 2e6e242

Browse files
committed
Add a test for iterators that capture but don't lend
1 parent 3eb7b78 commit 2e6e242

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ run-pass
2+
3+
#![feature(iter_macro, yield_expr)]
4+
5+
// This test creates an iterator that captures a reference and ensure that doesn't force the
6+
// iterator to become lending.
7+
8+
use std::iter::iter;
9+
10+
fn main() {
11+
let s = "foo".to_string();
12+
let f = iter! { || {
13+
for c in s.chars() {
14+
yield c;
15+
}
16+
}};
17+
18+
let mut i = f();
19+
let mut j = f();
20+
21+
assert_eq!(i.next(), Some('f'));
22+
assert_eq!(i.next(), Some('o'));
23+
assert_eq!(i.next(), Some('o'));
24+
assert_eq!(i.next(), None);
25+
26+
assert_eq!(j.next(), Some('f'));
27+
assert_eq!(j.next(), Some('o'));
28+
assert_eq!(j.next(), Some('o'));
29+
assert_eq!(j.next(), None);
30+
}

0 commit comments

Comments
 (0)