2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
struct closure_box<'a> {
|
2019-05-28 18:47:21 +00:00
|
|
|
cl: Box<dyn FnMut() + 'a>,
|
2012-08-20 23:53:33 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:47:21 +00:00
|
|
|
fn box_it<'a>(x: Box<dyn FnMut() + 'a>) -> closure_box<'a> {
|
2013-02-15 10:44:18 +00:00
|
|
|
closure_box {cl: x}
|
2012-08-20 23:53:33 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2015-03-03 08:42:26 +00:00
|
|
|
let mut i = 3;
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(i, 3);
|
2014-02-10 12:44:03 +00:00
|
|
|
{
|
2015-02-01 17:44:15 +00:00
|
|
|
let cl = || i += 1;
|
2015-02-15 08:52:21 +00:00
|
|
|
let mut cl_box = box_it(Box::new(cl));
|
2015-12-03 01:31:49 +00:00
|
|
|
(cl_box.cl)();
|
2014-02-10 12:44:03 +00:00
|
|
|
}
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(i, 4);
|
2012-08-20 23:53:33 +00:00
|
|
|
}
|