]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-55850.rs
Rollup merge of #60562 - iliekturtles:proc-macro-missing-docs, r=alexcrichton
[rust.git] / src / test / ui / nll / issue-55850.rs
1 #![allow(unused_mut)]
2 #![feature(generators, generator_trait)]
3
4 use std::marker::Unpin;
5 use std::ops::Generator;
6 use std::ops::GeneratorState::Yielded;
7 use std::pin::Pin;
8
9 pub struct GenIter<G>(G);
10
11 impl <G> Iterator for GenIter<G>
12 where
13     G: Generator + Unpin,
14 {
15     type Item = G::Yield;
16
17     fn next(&mut self) -> Option<Self::Item> {
18         match Pin::new(&mut self.0).resume() {
19             Yielded(y) => Some(y),
20             _ => None
21         }
22     }
23 }
24
25 fn bug<'a>() -> impl Iterator<Item = &'a str> {
26     GenIter(move || {
27         let mut s = String::new();
28         yield &s[..] //~ ERROR cannot yield value referencing local variable `s` [E0515]
29         //~| ERROR borrow may still be in use when generator yields
30     })
31 }
32
33 fn main() {
34     bug();
35 }