]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
Bootstrap it. Hard.
[rust.git] / tests / target / closure.rs
1 // Closures
2
3 fn main() {
4     let square = (|i: i32| i * i);
5
6     let commented = |// first
7                      a, // argument
8                      // second
9                      b: WithType, // argument
10                      // ignored
11                      _| {
12         (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
13     };
14
15     let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
16                            ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
17         xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
18     };
19
20     let loooooooooooooong_name = |field| {
21         // TODO(#27): format comments.
22         if field.node.attrs.len() > 0 {
23             field.node.attrs[0].span.lo
24         } else {
25             field.span.lo
26         }
27     };
28
29     let block_me = |field| if true_story() {
30         1
31     } else {
32         2
33     };
34
35     let unblock_me = |trivial| closure();
36
37     let empty = |arg| {};
38
39     let simple = |arg| {
40         // TODO(#27): comment formatting
41         foo(arg)
42     };
43
44     let test = || {
45         do_something();
46         do_something_else();
47     };
48
49     let arg_test =
50         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
51
52     let arg_test =
53         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
54
55     let simple_closure = move || -> () {};
56
57     let closure = |input: Ty| -> Option<String> { foo() };
58
59     let closure_with_return_type =
60         |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
61
62     |arg1, arg2, _, _, arg3, arg4| {
63         let temp = arg4 + arg3;
64         arg2 * arg1 - temp
65     }
66 }
67
68 fn issue311() {
69     let func = |x| println!("{}", x);
70
71     (func)(0.0);
72 }
73
74 fn issue863() {
75     let closure = |x| match x {
76         0 => true,
77         _ => false,
78     } == true;
79 }
80
81 fn issue934() {
82     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
83         let mut h = SpanlessHash::new(cx);
84         h.hash_block(block);
85         h.finish()
86     };
87
88     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
89         let mut h = SpanlessHash::new(cx);
90         h.hash_block(block);
91         h.finish();
92     };
93 }
94
95 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
96     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
97         match (&left.node, &right.node) {
98             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
99                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) ||
100                 swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
101                     l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
102                 })
103             }
104         }
105     }
106 }