2018-12-03 14:13:28 +01:00
|
|
|
#![allow(unused_mut)]
|
2023-10-19 21:46:28 +00:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2018-12-03 14:13:28 +01:00
|
|
|
|
2018-10-04 20:49:38 +02: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 20:49:38 +02:00
|
|
|
use std::pin::Pin;
|
2018-12-03 14:13:28 +01: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 14:13:28 +01:00
|
|
|
{
|
|
|
|
type Item = G::Yield;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
2020-01-25 20:03:10 +01:00
|
|
|
match Pin::new(&mut self.0).resume(()) {
|
2018-10-04 20:49:38 +02:00
|
|
|
Yielded(y) => Some(y),
|
|
|
|
_ => None
|
2018-12-03 14:13:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bug<'a>() -> impl Iterator<Item = &'a str> {
|
2024-04-11 13:15:34 +00:00
|
|
|
GenIter(#[coroutine] move || {
|
2018-12-03 14:13:28 +01:00
|
|
|
let mut s = String::new();
|
2019-04-22 18:20:19 +01: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 14:13:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
bug();
|
|
|
|
}
|