summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt/tests/target/closure.rs
blob: e8b4ff7a96bb8c004bd7011c663a0051041f87dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// rustfmt-normalize_comments: true
// Closures

fn main() {
    let square = (|i: i32| i * i);

    let commented = |// first
                     a, // argument
                     // second
                     b: WithType, // argument
                     // ignored
                     _| {
        (
            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
            bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
        )
    };

    let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
                           ref yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy| {
        xxxxxxxxxxxxxxxxxxxxxxxxxxxxx + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
    };

    let loooooooooooooong_name = |field| {
        // format comments.
        if field.node.attrs.len() > 0 {
            field.node.attrs[0].span.lo()
        } else {
            field.span.lo()
        }
    };

    let unblock_me = |trivial| closure();

    let empty = |arg| {};

    let simple = |arg| {
        // comment formatting
        foo(arg)
    };

    let test = || {
        do_something();
        do_something_else();
    };

    let arg_test =
        |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();

    let arg_test =
        |big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();

    let simple_closure = move || -> () {};

    let closure = |input: Ty| -> Option<String> { foo() };

    let closure_with_return_type =
        |aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };

    |arg1, arg2, _, _, arg3, arg4| {
        let temp = arg4 + arg3;
        arg2 * arg1 - temp
    };

    let block_body_with_comment = args.iter().map(|a| {
        // Emitting only dep-info is possible only for final crate type, as
        // as others may emit required metadata for dependent crate types
        if a.starts_with("--emit") && is_final_crate_type && !self.workspace_mode {
            "--emit=dep-info"
        } else {
            a
        }
    });

    for<> || -> () {};
    for<> || -> () {};
    for<> || -> () {};

    for<'a, 'b, 'c> |_: &'a (), _: &'b (), _: &'c ()| -> () {};
}

fn issue311() {
    let func = |x| println!("{}", x);

    (func)(0.0);
}

fn issue863() {
    let closure = |x| match x {
        0 => true,
        _ => false,
    } == true;
}

fn issue934() {
    let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
        let mut h = SpanlessHash::new(cx);
        h.hash_block(block);
        h.finish()
    };

    let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
        let mut h = SpanlessHash::new(cx);
        h.hash_block(block);
        h.finish();
    };
}

impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
    pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
        match (&left.node, &right.node) {
            (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
                l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
                    || 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)
                    })
            }
        }
    }
}

fn foo() {
    lifetimes_iter___map(|lasdfasfd| {
        let hi = if l.bounds.is_empty() {
            l.lifetime.span.hi()
        };
    });
}

fn issue1405() {
    open_raw_fd(fd, b'r').and_then(|file| {
        Capture::new_raw(None, |_, err| unsafe { raw::pcap_fopen_offline(file, err) })
    });
}

fn issue1466() {
    let vertex_buffer = frame.scope(|ctx| {
        let buffer = ctx.create_host_visible_buffer::<VertexBuffer<Vertex>>(&vertices);
        ctx.create_device_local_buffer(buffer)
    });
}

fn issue470() {
    {
        {
            {
                let explicit_arg_decls =
                    explicit_arguments
                        .into_iter()
                        .enumerate()
                        .map(|(index, (ty, pattern))| {
                            let lvalue = Lvalue::Arg(index as u32);
                            block = this.pattern(
                                block,
                                argument_extent,
                                hair::PatternRef::Hair(pattern),
                                &lvalue,
                            );
                            ArgDecl { ty: ty }
                        });
            }
        }
    }
}

// #1509
impl Foo {
    pub fn bar(&self) {
        Some(SomeType {
            push_closure_out_to_100_chars: iter(otherwise_it_works_ok.into_iter().map(|f| Ok(f))),
        })
    }
}

fn issue1329() {
    aaaaaaaaaaaaaaaa
        .map(|x| {
            x += 1;
            x
        })
        .filter
}

fn issue325() {
    let f =
        || unsafe { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx };
}

fn issue1697() {
    Test.func_a(
        A_VERY_LONG_CONST_VARIABLE_NAME,
        move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4,
    )
}

fn issue1694() {
    foooooo(
        |_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| {
            format!("refs/pull/{}/merge", pr_id)
        },
    )
}

fn issue1713() {
    rayon::join(
        || recurse(left, is_less, pred, limit),
        || recurse(right, is_less, Some(pivot), limit),
    );

    rayon::join(
        1,
        || recurse(left, is_less, pred, limit),
        2,
        || recurse(right, is_less, Some(pivot), limit),
    );
}

fn issue2063() {
    |ctx: Ctx<(String, String)>| -> io::Result<Response> {
        Ok(Response::new().with_body(ctx.params.0))
    }
}

fn issue1524() {
    let f = |x| x;
    let f = |x| x;
    let f = |x| x;
    let f = |x| x;
    let f = |x| x;
}

fn issue2171() {
    foo(|| unsafe {
        if PERIPHERALS {
            loop {}
        } else {
            PERIPHERALS = true;
        }
    })
}

fn issue2207() {
    a.map(|_| {
        unsafe { a_very_very_very_very_very_very_very_long_function_name_or_anything_else() }
            .to_string()
    })
}

fn issue2262() {
    result
        .init(&mut result.slave.borrow_mut(), &mut (result.strategy)())
        .map_err(|factory| Error {
            factory,
            slave: None,
        })?;
}