rust/tests/ui/coroutine/dropck-resume.rs

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

34 lines
720 B
Rust
Raw Normal View History

2023-10-19 16:46:28 -05:00
#![feature(coroutines, coroutine_trait)]
2020-01-27 16:26:37 -06:00
2023-10-19 11:06:43 -05:00
use std::ops::{Coroutine, CoroutineState};
2020-01-27 16:26:37 -06:00
use std::pin::Pin;
struct SetToNone<'a: 'b, 'b>(&'b mut Option<&'a i32>);
impl<'a, 'b> Drop for SetToNone<'a, 'b> {
fn drop(&mut self) {
*self.0 = None;
}
}
2023-10-19 16:46:28 -05:00
fn drop_using_coroutine() -> i32 {
2020-01-27 16:26:37 -06:00
let mut y = Some(&0);
let z = &mut y;
let r;
{
let mut g = move |r| {
let _s = SetToNone(r);
yield;
};
let mut g = Pin::new(&mut g);
g.as_mut().resume(z);
r = y.as_ref().unwrap();
//~^ ERROR cannot borrow `y` as immutable because it is also borrowed as mutable
}
**r
}
fn main() {
2023-10-19 16:46:28 -05:00
println!("{}", drop_using_coroutine());
2020-01-27 16:26:37 -06:00
}