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