summaryrefslogtreecommitdiffstats
path: root/src/test/ui/regions/regions-copy-closure.rs
blob: 43640079777a343cf5b81f86b64d3e0c96e6cec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// run-pass
#![allow(non_camel_case_types)]

struct closure_box<'a> {
    cl: Box<dyn FnMut() + 'a>,
}

fn box_it<'a>(x: Box<dyn FnMut() + 'a>) -> closure_box<'a> {
    closure_box {cl: x}
}

pub fn main() {
    let mut i = 3;
    assert_eq!(i, 3);
    {
        let cl = || i += 1;
        let mut cl_box = box_it(Box::new(cl));
        (cl_box.cl)();
    }
    assert_eq!(i, 4);
}