2018-12-03 13:13:28 +00:00
|
|
|
#![allow(unused_mut)]
|
2023-10-19 21:46:28 +00:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2018-12-03 13:13:28 +00:00
|
|
|
|
2018-10-04 18:49:38 +00:00
|
|
|
use std::marker::Unpin;
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::Coroutine;
|
|
|
|
use std::ops::CoroutineState::Yielded;
|
2018-10-04 18:49:38 +00:00
|
|
|
use std::pin::Pin;
|
2018-12-03 13:13:28 +00:00
|
|
|
|
|
|
|
pub struct GenIter<G>(G);
|
|
|
|
|
|
|
|
impl <G> Iterator for GenIter<G>
|
|
|
|
where
|
2023-10-19 16:06:43 +00:00
|
|
|
G: Coroutine + Unpin,
|
2018-12-03 13:13:28 +00:00
|
|
|
{
|
|
|
|
type Item = G::Yield;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
2020-01-25 19:03:10 +00:00
|
|
|
match Pin::new(&mut self.0).resume(()) {
|
2018-10-04 18:49:38 +00:00
|
|
|
Yielded(y) => Some(y),
|
|
|
|
_ => None
|
2018-12-03 13:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bug<'a>() -> impl Iterator<Item = &'a str> {
|
|
|
|
GenIter(move || {
|
|
|
|
let mut s = String::new();
|
2019-04-22 17:20:19 +00:00
|
|
|
yield &s[..] //~ ERROR cannot yield value referencing local variable `s` [E0515]
|
2023-10-19 21:46:28 +00:00
|
|
|
//~| ERROR borrow may still be in use when coroutine yields
|
2018-12-03 13:13:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
bug();
|
|
|
|
}
|