]> git.lizzy.rs Git - rust.git/blob - tests/ui/functions-closures/return-from-closure.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui / functions-closures / return-from-closure.rs
1 // run-pass
2 #![allow(non_upper_case_globals)]
3 // just to make sure that `return` is only returning from the closure,
4 // not the surrounding function.
5
6 static mut calls: usize = 0;
7
8 fn surrounding() {
9     let return_works = |n: isize| {
10         unsafe { calls += 1 }
11
12         if n >= 0 { return; }
13         panic!()
14     };
15
16     return_works(10);
17     return_works(20);
18
19     let return_works_proc = |n: isize| {
20         unsafe { calls += 1 }
21
22         if n >= 0 { return; }
23         panic!()
24     };
25
26     return_works_proc(10);
27 }
28
29 pub fn main() {
30     surrounding();
31
32     assert_eq!(unsafe {calls}, 3);
33 }