rust/src/test/ui/nll/issue-55850.rs

35 lines
672 B
Rust
Raw Normal View History

#![allow(unused_mut)]
#![feature(generators, generator_trait)]
2018-10-04 18:49:38 +00:00
use std::marker::Unpin;
use std::ops::Generator;
use std::ops::GeneratorState::Yielded;
2018-10-04 18:49:38 +00:00
use std::pin::Pin;
pub struct GenIter<G>(G);
impl <G> Iterator for GenIter<G>
where
2018-10-04 18:49:38 +00:00
G: Generator + Unpin,
{
type Item = G::Yield;
fn next(&mut self) -> Option<Self::Item> {
2018-10-04 18:49:38 +00:00
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 `s` does not live long enough [E0597]
})
}
fn main() {
bug();
}