]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-55850.rs
Rollup merge of #57856 - lzutao:fix-old-first-edition, r=steveklabnik
[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 `s` does not live long enough [E0597]
29     })
30 }
31
32 fn main() {
33     bug();
34 }