rust/tests/ui/nll/issue-55850.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
762 B
Rust
Raw Normal View History

#![allow(unused_mut)]
2023-10-19 21:46:28 +00:00
#![feature(coroutines, coroutine_trait)]
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;
pub struct GenIter<G>(G);
impl <G> Iterator for GenIter<G>
where
2023-10-19 16:06:43 +00:00
G: Coroutine + Unpin,
{
type Item = G::Yield;
fn next(&mut self) -> Option<Self::Item> {
match Pin::new(&mut self.0).resume(()) {
2018-10-04 18:49:38 +00:00
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]
2023-10-19 21:46:28 +00:00
//~| ERROR borrow may still be in use when coroutine yields
})
}
fn main() {
bug();
}