]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
Fix static async closure qualifier order
[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     let block_body_with_comment = args.iter().map(|a| {
66         // Emitting only dep-info is possible only for final crate type, as
67         // as others may emit required metadata for dependent crate types
68         if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode {
69             "--emit=dep-info"
70         } else {
71             a
72         }
73     });
74 }
75
76 fn issue311() {
77     let func = |x| println!("{}", x);
78
79     (func)(0.0);
80 }
81
82 fn issue863() {
83     let closure = |x| match x {
84         0 => true,
85         _ => false,
86     } == true;
87 }
88
89 fn issue934() {
90     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
91         let mut h = SpanlessHash::new(cx);
92         h.hash_block(block);
93         h.finish()
94     };
95
96     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
97         let mut h = SpanlessHash::new(cx);
98         h.hash_block(block);
99         h.finish();
100     };
101 }
102
103 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
104     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
105         match (&left.node, &right.node) {
106             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
107                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
108                     || swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
109                         l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
110                     })
111             }
112         }
113     }
114 }
115
116 fn foo() {
117     lifetimes_iter___map(|lasdfasfd| {
118         let hi = if l.bounds.is_empty() {
119             l.lifetime.span.hi()
120         };
121     });
122 }
123
124 fn issue1405() {
125     open_raw_fd(fd, b'r').and_then(|file| {
126         Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) })
127     });
128 }
129
130 fn issue1466() {
131     let vertex_buffer = frame.scope(|ctx| {
132         let buffer = ctx.create_host_visible_buffer::<VertexBuffer<Vertex>>(&vertices);
133         ctx.create_device_local_buffer(buffer)
134     });
135 }
136
137 fn issue470() {
138     {
139         {
140             {
141                 let explicit_arg_decls =
142                     explicit_arguments
143                         .into_iter()
144                         .enumerate()
145                         .map(|(index, (ty, pattern))| {
146                             let lvalue = Lvalue::Arg(index as u32);
147                             block = this.pattern(
148                                 block,
149                                 argument_extent,
150                                 hair::PatternRef::Hair(pattern),
151                                 &lvalue,
152                             );
153                             ArgDecl { ty: ty }
154                         });
155             }
156         }
157     }
158 }
159
160 // #1509
161 impl Foo {
162     pub fn bar(&self) {
163         Some(SomeType {
164             push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| Ok(f))),
165         })
166     }
167 }
168
169 fn issue1329() {
170     aaaaaaaaaaaaaaaa
171         .map(|x| {
172             x += 1;
173             x
174         })
175         .filter
176 }
177
178 fn issue325() {
179     let f =
180         || unsafe { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx };
181 }
182
183 fn issue1697() {
184     Test.func_a(
185         A_VERY_LONG_CONST_VARIABLE_NAME,
186         move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4,
187     )
188 }
189
190 fn issue1694() {
191     foooooo(
192         |_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| {
193             format!("refs/pull/{}/merge", pr_id)
194         },
195     )
196 }
197
198 fn issue1713() {
199     rayon::join(
200         || recurse(left, is_less, pred, limit),
201         || recurse(right, is_less, Some(pivot), limit),
202     );
203
204     rayon::join(
205         1,
206         || recurse(left, is_less, pred, limit),
207         2,
208         || recurse(right, is_less, Some(pivot), limit),
209     );
210 }
211
212 fn issue2063() {
213     |ctx: Ctx<(String, String)>| -> io::Result<Response> {
214         Ok(Response::new().with_body(ctx.params.0))
215     }
216 }
217
218 fn issue1524() {
219     let f = |x| x;
220     let f = |x| x;
221     let f = |x| x;
222     let f = |x| x;
223     let f = |x| x;
224 }
225
226 fn issue2171() {
227     foo(|| unsafe {
228         if PERIPHERALS {
229             loop {}
230         } else {
231             PERIPHERALS = true;
232         }
233     })
234 }
235
236 fn issue2207() {
237     a.map(|_| {
238         unsafe { a_very_very_very_very_very_very_very_long_function_name_or_anything_else() }
239             .to_string()
240     })
241 }
242
243 fn issue2262() {
244     result
245         .init(&mut result.slave.borrow_mut(), &mut (result.strategy)())
246         .map_err(|factory| Error {
247             factory,
248             slave: None,
249         })?;
250 }