summaryrefslogtreecommitdiffstats
path: root/src/test/ui/span/issue-23729.rs
blob: ca33f9c77308b9b48924f0c0da114bf87c2b5ac8 (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
31
32
33
// Regression test for #23729

fn main() {
    let fib = {
        struct Recurrence {
            mem: [u64; 2],
            pos: usize,
        }

        impl Iterator for Recurrence {
            //~^ ERROR E0046
            #[inline]
            fn next(&mut self) -> Option<u64> {
                if self.pos < 2 {
                    let next_val = self.mem[self.pos];
                    self.pos += 1;
                    Some(next_val)
                } else {
                    let next_val = self.mem[0] + self.mem[1];
                    self.mem[0] = self.mem[1];
                    self.mem[1] = next_val;
                    Some(next_val)
                }
            }
        }

        Recurrence { mem: [0, 1], pos: 0 }
    };

    for e in fib.take(10) {
        println!("{}", e)
    }
}