summaryrefslogtreecommitdiffstats
path: root/tests/ui/generator/dropck-resume.rs
blob: 4c18077f33573e79aeb48647ddd7bb55f6db4580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#![feature(generators, generator_trait)]

use std::ops::{Generator, GeneratorState};
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;
    }
}

fn drop_using_generator() -> i32 {
    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() {
    println!("{}", drop_using_generator());
}