2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2018-08-31 15:02:01 +02:00
|
|
|
#![allow(non_upper_case_globals)]
|
2013-12-18 00:06:20 +11:00
|
|
|
// just to make sure that `return` is only returning from the closure,
|
|
|
|
// not the surrounding function.
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
static mut calls: usize = 0;
|
2013-12-18 00:06:20 +11:00
|
|
|
|
|
|
|
fn surrounding() {
|
2015-03-25 17:06:52 -07:00
|
|
|
let return_works = |n: isize| {
|
2013-12-18 00:06:20 +11:00
|
|
|
unsafe { calls += 1 }
|
|
|
|
|
|
|
|
if n >= 0 { return; }
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!()
|
2013-12-18 00:06:20 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
return_works(10);
|
|
|
|
return_works(20);
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
let return_works_proc = |n: isize| {
|
2013-12-18 00:06:20 +11:00
|
|
|
unsafe { calls += 1 }
|
|
|
|
|
|
|
|
if n >= 0 { return; }
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!()
|
2013-12-18 00:06:20 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
return_works_proc(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
surrounding();
|
|
|
|
|
|
|
|
assert_eq!(unsafe {calls}, 3);
|
|
|
|
}
|