mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
36 lines
762 B
Rust
36 lines
762 B
Rust
#![allow(unused_mut)]
|
|
#![feature(coroutines, coroutine_trait)]
|
|
|
|
use std::marker::Unpin;
|
|
use std::ops::Coroutine;
|
|
use std::ops::CoroutineState::Yielded;
|
|
use std::pin::Pin;
|
|
|
|
pub struct GenIter<G>(G);
|
|
|
|
impl <G> Iterator for GenIter<G>
|
|
where
|
|
G: Coroutine + 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 coroutine yields
|
|
})
|
|
}
|
|
|
|
fn main() {
|
|
bug();
|
|
}
|