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