]> git.lizzy.rs Git - rust.git/blob - tests/target/expr.rs
Refactor pairs/binops
[rust.git] / tests / target / expr.rs
1 // rustfmt-wrap_comments: true
2 // Test expressions
3
4 fn foo() -> bool {
5     let boxed: Box<i32> = box 5;
6     let referenced = &5;
7
8     let very_long_variable_name = (a + first + simple + test);
9     let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA +
10                                    BBBBBBBBBBBBBBBBB + b + c);
11
12     let is_internalxxxx = self.codemap.span_to_filename(s) ==
13                           self.codemap.span_to_filename(m.inner);
14
15     let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb /
16                    (bbbbbb - function_call(x, *very_long_pointer, y)) + 1000;
17
18     some_ridiculously_loooooooooooooooooooooong_function(10000 * 30000000000 +
19                                                          40000 / 1002200000000 -
20                                                          50000 * sqrt(-1),
21                                                          trivial_value);
22     (((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
23              a +
24              aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
25              aaaaa)))))))));
26
27     {
28         for _ in 0..10 {}
29     }
30
31     {
32         {
33             {
34                 {}
35             }
36         }
37     }
38
39     if 1 + 2 > 0 {
40         let result = 5;
41         result
42     } else {
43         4
44     };
45
46     if let Some(x) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
47         // Nothing
48     }
49
50     if let Some(x) = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
51                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
52
53     if let (some_very_large,
54             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
55     }
56
57     if let (some_very_large,
58             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) =
59         1111 + 2222 {}
60
61     if let (some_very_large,
62             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
63     }
64
65     let test = if true { 5 } else { 3 };
66
67     if cond() {
68         something();
69     } else if different_cond() {
70         something_else();
71     } else {
72         // Check subformatting
73         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
74         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
75     }
76 }
77
78 fn bar() {
79     let range = (111111111 + 333333333333333333 + 1111 + 400000000000000000)..
80                 (2222 + 2333333333333333);
81
82     let another_range = 5..some_func(a, b /* comment */);
83
84     for _ in 1.. {
85         call_forever();
86     }
87
88     syntactically_correct(loop {
89                               sup('?');
90                           },
91                           if cond { 0 } else { 1 });
92
93     let third = ..10;
94     let infi_range = ..;
95     let foo = 1..;
96     let bar = 5;
97     let nonsense = (10..0)..(0..10);
98
99     loop {
100         if true {
101             break;
102         }
103     }
104
105     let x = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
106              a);
107 }
108
109 fn baz() {
110     unsafe /* {}{}{}{{{{}} */ {
111         let foo = 1u32;
112     }
113
114     unsafe /* very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
115             * comment */ {
116     }
117
118     unsafe /* So this is a very long comment.
119             * Multi-line, too.
120             * Will it still format correctly? */ {
121     }
122
123     unsafe {
124         // Regular unsafe block
125     }
126
127     unsafe { foo() }
128
129     unsafe {
130         foo();
131     }
132 }
133
134 // Test some empty blocks.
135 fn qux() {
136     {}
137     // FIXME this one could be done better.
138     {
139         // a block with a comment
140     }
141     {
142
143     }
144     {
145         // A block with a comment.
146     }
147 }
148
149 fn issue227() {
150     {
151         let handler = box DocumentProgressHandler::new(addr,
152                                                        DocumentProgressTask::DOMContentLoaded);
153     }
154 }
155
156 fn issue184(source: &str) {
157     for c in source.chars() {
158         if index < 'a' {
159             continue;
160         }
161     }
162 }
163
164 fn arrays() {
165     let x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 7, 8, 9, 0, 1, 2, 3,
166              4, 5, 6, 7, 8, 9, 0];
167
168     let y = [// comment
169              1,
170              2, // post comment
171              3];
172
173     let xy = [strukt {
174                   test123: value_one_two_three_four,
175                   turbo: coolio(),
176               },
177               // comment
178               1];
179
180     let a = WeightedChoice::new(&mut [Weighted {
181                                           weight: x,
182                                           item: 0,
183                                       },
184                                       Weighted {
185                                           weight: 1,
186                                           item: 1,
187                                       },
188                                       Weighted {
189                                           weight: x,
190                                           item: 2,
191                                       },
192                                       Weighted {
193                                           weight: 1,
194                                           item: 3,
195                                       }]);
196
197     let z =
198         [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
199
200     [1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
201 }
202
203 fn returns() {
204     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
205     return;
206
207     return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
208            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
209 }
210
211 fn addrof() {
212     &mut (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
213           bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
214     &(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
215       bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
216 }
217
218 fn casts() {
219     fn unpack(packed: u32) -> [u16; 2] {
220         [(packed >> 16) as u16, (packed >> 0) as u16]
221     }
222
223     let some_trait_xxx = xxxxxxxxxxx + xxxxxxxxxxxxx as SomeTraitXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;
224     let slightly_longer_trait = yyyyyyyyy +
225                                 yyyyyyyyyyy as SomeTraitYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY;
226 }
227
228 fn indices() {
229     let x = (aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc)
230                 [x + y + z];
231     let y = (aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc)
232                 [xxxxx + yyyyy + zzzzz];
233 }
234
235 fn repeats() {
236     let x = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc;
237              x + y + z];
238     let y = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc;
239              xxxxx + yyyyy + zzzzz];
240 }
241
242 fn blocks() {
243     if 1 + 1 == 2 {
244         println!("yay arithmetix!");
245     };
246 }
247
248 fn issue767() {
249     if false {
250         if false {
251         } else {
252             // A let binding here seems necessary to trigger it.
253             let _ = ();
254         }
255     } else if let false = false {
256     }
257 }
258
259 fn ranges() {
260     let x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
261     let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
262             bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
263     let z = ...x;
264
265     a...b
266
267     // the expr below won't compile for some reason...
268     // let a = 0 ... ;
269 }
270
271 fn if_else() {
272     let exact = diff / (if size == 0 { 1 } else { size });
273
274     let cx = tp1.x + any * radius * if anticlockwise { 1.0 } else { -1.0 };
275 }
276
277 fn complex_if_else() {
278     if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
279     } else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
280         ha();
281     } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
282         yo();
283     } else if let Some(x) =
284         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
285         ha();
286     } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
287               xxxxxxxxx {
288         yo();
289     }
290 }
291
292 fn issue1106() {
293     {
294         if let hir::ItemEnum(ref enum_def, ref generics) =
295             self.ast_map.expect_item(enum_node_id).node {
296         }
297     }
298
299     for entry in WalkDir::new(path)
300         .into_iter()
301         .filter_entry(|entry| exclusions.filter_entry(entry)) {
302     }
303 }