about summary refs log tree commit diff
path: root/tests/ui/iterators/generator_capture_no_lend.rs
blob: 822db58d48df2e05ea6b4d257a8e6cff5deb4723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//@ run-pass

#![feature(iter_macro, yield_expr)]

// This test creates an iterator that captures a reference and ensure that doesn't force the
// iterator to become lending.

use std::iter::iter;

fn main() {
    let s = "foo".to_string();
    let f = iter! { || {
        for c in s.chars() {
            yield c;
        }
    }};

    let mut i = f();
    let mut j = f();

    assert_eq!(i.next(), Some('f'));
    assert_eq!(i.next(), Some('o'));
    assert_eq!(i.next(), Some('o'));
    assert_eq!(i.next(), None);

    assert_eq!(j.next(), Some('f'));
    assert_eq!(j.next(), Some('o'));
    assert_eq!(j.next(), Some('o'));
    assert_eq!(j.next(), None);
}