]> git.lizzy.rs Git - rust.git/blob - tests/target/expr.rs
Fix bug in identifying comments
[rust.git] / tests / target / expr.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-wrap_comments: true
3 // Test expressions
4
5 fn foo() -> bool {
6     let boxed: Box<i32> = box 5;
7     let referenced = &5;
8
9     let very_long_variable_name = (a + first + simple + test);
10     let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA +
11                                    BBBBBBBBBBBBBBBBB + b + c);
12
13     let is_internalxxxx = self.codemap.span_to_filename(s) ==
14                           self.codemap.span_to_filename(m.inner);
15
16     let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb /
17                    (bbbbbb - function_call(x, *very_long_pointer, y)) + 1000;
18
19     some_ridiculously_loooooooooooooooooooooong_function(10000 * 30000000000 +
20                                                          40000 / 1002200000000 -
21                                                          50000 * sqrt(-1),
22                                                          trivial_value);
23     (((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
24              a +
25              aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
26              aaaaa)))))))));
27
28     {
29         for _ in 0..10 {}
30     }
31
32     {
33         {
34             {
35                 {}
36             }
37         }
38     }
39
40     if 1 + 2 > 0 {
41         let result = 5;
42         result
43     } else {
44         4
45     };
46
47     if let Some(x) = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
48         // Nothing
49     }
50
51     if let Some(x) = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
52                       aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
53
54     if let (some_very_large,
55             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
56     }
57
58     if let (some_very_large,
59             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) =
60         1111 + 2222 {}
61
62     if let (some_very_large,
63             tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {}
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     { /* a block with a comment */ }
139     {}
140     {
141         // A block with a comment.
142     }
143 }
144
145 fn issue227() {
146     {
147         let handler = box DocumentProgressHandler::new(addr,
148                                                        DocumentProgressTask::DOMContentLoaded);
149     }
150 }
151
152 fn issue184(source: &str) {
153     for c in source.chars() {
154         if index < 'a' {
155             continue;
156         }
157     }
158 }
159
160 fn arrays() {
161     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,
162              4, 5, 6, 7, 8, 9, 0];
163
164     let y = [// comment
165              1,
166              2, // post comment
167              3];
168
169     let xy = [strukt {
170                   test123: value_one_two_three_four,
171                   turbo: coolio(),
172               },
173               // comment
174               1];
175
176     let a = WeightedChoice::new(&mut [Weighted {
177                                           weight: x,
178                                           item: 0,
179                                       },
180                                       Weighted {
181                                           weight: 1,
182                                           item: 1,
183                                       },
184                                       Weighted {
185                                           weight: x,
186                                           item: 2,
187                                       },
188                                       Weighted {
189                                           weight: 1,
190                                           item: 3,
191                                       }]);
192
193     let z =
194         [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
195
196     [1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
197 }
198
199 fn returns() {
200     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
201     return;
202
203     return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
204            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
205 }
206
207 fn addrof() {
208     &mut (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
209           bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
210     &(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
211       bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
212 }
213
214 fn casts() {
215     fn unpack(packed: u32) -> [u16; 2] {
216         [(packed >> 16) as u16, (packed >> 0) as u16]
217     }
218
219     let some_trait_xxx = xxxxxxxxxxx + xxxxxxxxxxxxx as SomeTraitXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;
220     let slightly_longer_trait = yyyyyyyyy +
221                                 yyyyyyyyyyy as SomeTraitYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY;
222 }
223
224 fn indices() {
225     let x = (aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc)
226                 [x + y + z];
227     let y = (aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc)
228                 [xxxxx + yyyyy + zzzzz];
229 }
230
231 fn repeats() {
232     let x = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc;
233              x + y + z];
234     let y = [aaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccc;
235              xxxxx + yyyyy + zzzzz];
236 }
237
238 fn blocks() {
239     if 1 + 1 == 2 {
240         println!("yay arithmetix!");
241     };
242 }
243
244 fn issue767() {
245     if false {
246         if false {
247         } else {
248             // A let binding here seems necessary to trigger it.
249             let _ = ();
250         }
251     } else if let false = false {
252     }
253 }
254
255 fn ranges() {
256     let x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
257     let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
258             bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
259     let z = ...x;
260
261     a...b
262
263     // the expr below won't compile for some reason...
264     // let a = 0 ... ;
265 }
266
267 fn if_else() {
268     let exact = diff / (if size == 0 { 1 } else { size });
269
270     let cx = tp1.x + any * radius * if anticlockwise { 1.0 } else { -1.0 };
271 }
272
273 fn complex_if_else() {
274     if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
275     } else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
276         ha();
277     } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
278         yo();
279     } else if let Some(x) =
280         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
281         ha();
282     } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
283               xxxxxxxxx {
284         yo();
285     }
286 }
287
288 fn issue1106() {
289     {
290         if let hir::ItemEnum(ref enum_def, ref generics) =
291             self.ast_map.expect_item(enum_node_id).node {}
292     }
293
294     for entry in WalkDir::new(path)
295         .into_iter()
296         .filter_entry(|entry| exclusions.filter_entry(entry)) {}
297 }