]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/myriad-closures.rs
Auto merge of #37834 - bluss:peek-none, r=BurntSushi
[rust.git] / src / test / run-pass / myriad-closures.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // This test case tests whether we can handle code bases that contain a high
12 // number of closures, something that needs special handling in the MingGW
13 // toolchain.
14 // See https://github.com/rust-lang/rust/issues/34793 for more information.
15
16 // Expand something exponentially
17 macro_rules! go_bacterial {
18     ($mac:ident) => ($mac!());
19     ($mac:ident 1 $($t:tt)*) => (
20         go_bacterial!($mac $($t)*);
21         go_bacterial!($mac $($t)*);
22     )
23 }
24
25 macro_rules! mk_closure {
26     () => ({
27         let c = |a: u32| a + 4;
28         let _ = c(2);
29     })
30 }
31
32 macro_rules! mk_fn {
33     () => {
34         {
35             fn function() {
36                 // Make 16 closures
37                 go_bacterial!(mk_closure 1 1 1 1);
38             }
39             let _ = function();
40         }
41     }
42 }
43
44 fn main() {
45     // Make 2^12 functions, each containing 16 closures,
46     // resulting in 2^16 closures overall.
47     go_bacterial!(mk_fn 1 1 1 1  1 1 1 1  1 1 1 1);
48 }