]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
Only read the trailing comma of outermost fn call
[rust.git] / tests / target / 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
8                      a, // argument
9                      // second
10                      b: WithType, // argument
11                      // ignored
12                      _| {
13         (
14             aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
15             bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
16         )
17     };
18
19     let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
20                            ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
21         xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
22     };
23
24     let loooooooooooooong_name = |field| {
25         // format comments.
26         if field.node.attrs.len() > 0 {
27             field.node.attrs[0].span.lo()
28         } else {
29             field.span.lo()
30         }
31     };
32
33     let unblock_me = |trivial| closure();
34
35     let empty = |arg| {};
36
37     let simple = |arg| {
38         // comment formatting
39         foo(arg)
40     };
41
42     let test = || {
43         do_something();
44         do_something_else();
45     };
46
47     let arg_test =
48         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
49
50     let arg_test =
51         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
52
53     let simple_closure = move || -> () {};
54
55     let closure = |input: Ty| -> Option<String> { foo() };
56
57     let closure_with_return_type =
58         |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
59
60     |arg1, arg2, _, _, arg3, arg4| {
61         let temp = arg4 + arg3;
62         arg2 * arg1 - temp
63     }
64 }
65
66 fn issue311() {
67     let func = |x| println!("{}", x);
68
69     (func)(0.0);
70 }
71
72 fn issue863() {
73     let closure = |x| match x {
74         0 => true,
75         _ => false,
76     } == true;
77 }
78
79 fn issue934() {
80     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
81         let mut h = SpanlessHash::new(cx);
82         h.hash_block(block);
83         h.finish()
84     };
85
86     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
87         let mut h = SpanlessHash::new(cx);
88         h.hash_block(block);
89         h.finish();
90     };
91 }
92
93 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
94     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
95         match (&left.node, &right.node) {
96             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
97                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
98                     || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
99                         l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
100                     })
101             }
102         }
103     }
104 }
105
106 fn foo() {
107     lifetimes_iter___map(|lasdfasfd| {
108         let hi = if l.bounds.is_empty() {
109             l.lifetime.span.hi()
110         };
111     });
112 }
113
114 fn issue1405() {
115     open_raw_fd(fd, b'r').and_then(|file| {
116         Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) })
117     });
118 }
119
120 fn issue1466() {
121     let vertex_buffer = frame.scope(|ctx| {
122         let buffer = ctx.create_host_visible_buffer::<VertexBuffer<Vertex>>(&vertices);
123         ctx.create_device_local_buffer(buffer)
124     });
125 }
126
127 fn issue470() {
128     {
129         {
130             {
131                 let explicit_arg_decls = explicit_arguments.into_iter().enumerate().map(
132                     |(index, (ty, pattern))| {
133                         let lvalue = Lvalue::Arg(index as u32);
134                         block = this.pattern(
135                             block,
136                             argument_extent,
137                             hair::PatternRef::Hair(pattern),
138                             &lvalue,
139                         );
140                         ArgDecl { ty: ty }
141                     },
142                 );
143             }
144         }
145     }
146 }
147
148 // #1509
149 impl Foo {
150     pub fn bar(&self) {
151         Some(SomeType {
152             push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| Ok(f))),
153         })
154     }
155 }
156
157 fn issue1329() {
158     aaaaaaaaaaaaaaaa
159         .map(|x| {
160             x += 1;
161             x
162         })
163         .filter
164 }
165
166 fn issue325() {
167     let f =
168         || unsafe { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx };
169 }
170
171 fn issue1697() {
172     Test.func_a(
173         A_VERY_LONG_CONST_VARIABLE_NAME,
174         move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4,
175     )
176 }
177
178 fn issue1694() {
179     foooooo(
180         |_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| {
181             format!("refs/pull/{}/merge", pr_id)
182         },
183     )
184 }
185
186 fn issue1713() {
187     rayon::join(
188         || recurse(left, is_less, pred, limit),
189         || recurse(right, is_less, Some(pivot), limit),
190     );
191
192     rayon::join(
193         1,
194         || recurse(left, is_less, pred, limit),
195         2,
196         || recurse(right, is_less, Some(pivot), limit),
197     );
198 }
199
200 fn issue2063() {
201     |ctx: Ctx<(String, String)>| -> io::Result<Response> {
202         Ok(Response::new().with_body(ctx.params.0))
203     }
204 }