]> git.lizzy.rs Git - rust.git/blob - tests/target/closure.rs
Add fallback path
[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 =
8         |// first
9          a, // argument
10          // second
11          b: WithType, // argument
12          // ignored
13          _| (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
14
15     let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
16                            ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
17         xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
18     };
19
20     let loooooooooooooong_name = |field| {
21         // 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 unblock_me = |trivial| closure();
30
31     let empty = |arg| {};
32
33     let simple = |arg| {
34         // comment formatting
35         foo(arg)
36     };
37
38     let test = || {
39         do_something();
40         do_something_else();
41     };
42
43     let arg_test =
44         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
45
46     let arg_test =
47         |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
48
49     let simple_closure = move || -> () {};
50
51     let closure = |input: Ty| -> Option<String> { foo() };
52
53     let closure_with_return_type =
54         |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
55
56     |arg1, arg2, _, _, arg3, arg4| {
57         let temp = arg4 + arg3;
58         arg2 * arg1 - temp
59     }
60 }
61
62 fn issue311() {
63     let func = |x| println!("{}", x);
64
65     (func)(0.0);
66 }
67
68 fn issue863() {
69     let closure = |x| match x {
70         0 => true,
71         _ => false,
72     } == true;
73 }
74
75 fn issue934() {
76     let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
77         let mut h = SpanlessHash::new(cx);
78         h.hash_block(block);
79         h.finish()
80     };
81
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
89 impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
90     pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
91         match (&left.node, &right.node) {
92             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
93                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr) ||
94                 swap_binop(l_op.node, ll, lr).map_or(false, |(l_op, ll, lr)| {
95                     l_op == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
96                 })
97             }
98         }
99     }
100 }
101
102 fn foo() {
103     lifetimes_iter___map(|lasdfasfd| {
104                              let hi = if l.bounds.is_empty() {
105                                  l.lifetime.span.hi
106                              };
107                          });
108 }
109
110 fn issue1405() {
111     open_raw_fd(fd, b'r').and_then(|file| {
112         Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) })
113     });
114 }
115
116 fn issue1466() {
117     let vertex_buffer = frame.scope(|ctx| {
118         let buffer = ctx.create_host_visible_buffer::<VertexBuffer<Vertex>>(&vertices);
119         ctx.create_device_local_buffer(buffer)
120     });
121 }
122
123 fn issue470() {
124     {
125         {
126             {
127                 let explicit_arg_decls = explicit_arguments
128                     .into_iter()
129                     .enumerate()
130                     .map(|(index, (ty, pattern))| {
131                              let lvalue = Lvalue::Arg(index as u32);
132                              block = this.pattern(block,
133                                                   argument_extent,
134                                                   hair::PatternRef::Hair(pattern),
135                                                   &lvalue);
136                              ArgDecl { ty: ty }
137                          });
138             }
139         }
140     }
141 }
142
143 // #1509
144 impl Foo {
145     pub fn bar(&self) {
146         Some(SomeType {
147                  push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| {
148                                                                                                Ok(f)
149                                                                                            })),
150              })
151     }
152 }