summaryrefslogtreecommitdiffstats
path: root/src/test/ui/nll/issue-55850.rs
blob: e6279bd028e01008a12dca339f8f2d9992d2bafc (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
34
35
#![allow(unused_mut)]
#![feature(generators, generator_trait)]

use std::marker::Unpin;
use std::ops::Generator;
use std::ops::GeneratorState::Yielded;
use std::pin::Pin;

pub struct GenIter<G>(G);

impl <G> Iterator for GenIter<G>
where
    G: Generator + Unpin,
{
    type Item = G::Yield;

    fn next(&mut self) -> Option<Self::Item> {
        match Pin::new(&mut self.0).resume(()) {
            Yielded(y) => Some(y),
            _ => None
        }
    }
}

fn bug<'a>() -> impl Iterator<Item = &'a str> {
    GenIter(move || {
        let mut s = String::new();
        yield &s[..] //~ ERROR cannot yield value referencing local variable `s` [E0515]
        //~| ERROR borrow may still be in use when generator yields
    })
}

fn main() {
    bug();
}