]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
Merge pull request #2265 from topecongiro/issue-2262
[rust.git] / tests / target / macros.rs
1 // rustfmt-normalize_comments: true
2 itemmacro!(this, is.now().formatted(yay));
3
4 itemmacro!(
5     really,
6     long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb()
7         .is
8         .formatted()
9 );
10
11 itemmacro!{this, is.bracket().formatted()}
12
13 peg_file! modname("mygrammarfile.rustpeg");
14
15 fn main() {
16     foo!();
17
18     bar!(a, b, c);
19
20     bar!(a, b, c,);
21
22     baz!(1 + 2 + 3, quux.kaas());
23
24     quux!(
25         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
26         BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
27     );
28
29     kaas!(
30         // comments
31         a, // post macro
32         b  // another
33     );
34
35     trailingcomma!(a, b, c,);
36     // Preserve trailing comma only when necessary.
37     ok!(file.seek(SeekFrom::Start(
38         table.map(|table| fixture.offset(table)).unwrap_or(0),
39     )));
40
41     noexpr!( i am not an expression, OK? );
42
43     vec![a, b, c];
44
45     vec![
46         AAAAAA,
47         AAAAAA,
48         AAAAAA,
49         AAAAAA,
50         AAAAAA,
51         AAAAAA,
52         AAAAAA,
53         AAAAAA,
54         AAAAAA,
55         BBBBB,
56         5,
57         100 - 30,
58         1.33,
59         b,
60         b,
61         b,
62     ];
63
64     vec![a /* comment */];
65
66     // Trailing spaces after a comma
67     vec![a];
68
69     vec![a; b];
70     vec![a; b];
71     vec![a; b];
72
73     vec![a, b; c];
74     vec![a; b, c];
75
76     vec![
77         a;
78         (|x| {
79             let y = x + 1;
80             let z = y + 1;
81             z
82         })(2)
83     ];
84     vec![
85         a;
86         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
87     ];
88     vec![a; unsafe { x + 1 }];
89
90     unknown_bracket_macro__comma_should_not_be_stripped![a,];
91
92     foo(makro!(1, 3));
93
94     hamkaas!{ () };
95
96     macrowithbraces! {dont,    format, me}
97
98     x!(fn);
99
100     some_macro!();
101
102     some_macro![];
103
104     some_macro!{
105         // comment
106     };
107
108     some_macro!{
109         // comment
110     };
111
112     some_macro!(
113         // comment
114         not function like
115     );
116
117     // #1712
118     let image = gray_image!(
119         00, 01, 02;
120         10, 11, 12;
121         20, 21, 22);
122
123     // #1092
124     chain!(input, a: take!(max_size), || []);
125 }
126
127 impl X {
128     empty_invoc!{}
129 }
130
131 fn issue_1279() {
132     println!("dsfs"); // a comment
133 }
134
135 fn issue_1555() {
136     let hello = &format!(
137         "HTTP/1.1 200 OK\r\nServer: {}\r\n\r\n{}",
138         "65454654654654654654654655464", "4"
139     );
140 }
141
142 fn issue1178() {
143     macro_rules! foo {
144         (#[$attr:meta] $name:ident) => {}
145     }
146
147     foo!(
148         #[doc = "bar"]
149         baz
150     );
151 }
152
153 fn issue1739() {
154     sql_function!(
155         add_rss_item,
156         add_rss_item_t,
157         (
158             a: types::Integer,
159             b: types::Timestamptz,
160             c: types::Text,
161             d: types::Text,
162             e: types::Text
163         )
164     );
165
166     w.slice_mut(s![
167         ..,
168         init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1],
169         ..
170     ]).par_map_inplace(|el| *el = 0.);
171 }
172
173 fn issue_1885() {
174     let threads = people
175         .into_iter()
176         .map(|name| {
177             chan_select! {
178                 rx.recv() => {}
179             }
180         })
181         .collect::<Vec<_>>();
182 }
183
184 fn issue_1917() {
185     mod x {
186         quickcheck! {
187             fn test(a: String, s: String, b: String) -> TestResult {
188                 if a.find(&s).is_none() {
189
190                     TestResult::from_bool(true)
191                 } else {
192                     TestResult::discard()
193                 }
194             }
195         }
196     }
197 }
198
199 fn issue_1921() {
200     // Macro with tabs.
201     lazy_static! {
202         static ref ONE: u32 = 1;
203         static ref TWO: u32 = 2;
204         static ref THREE: u32 = 3;
205         static ref FOUR: u32 = {
206             let mut acc = 1;
207             acc += 1;
208             acc += 2;
209             acc
210         }
211     }
212 }
213
214 // #1577
215 fn issue1577() {
216     let json = json!({
217         "foo": "bar",
218     });
219 }
220
221 gfx_pipeline!(pipe {
222     vbuf: gfx::VertexBuffer<Vertex> = (),
223     out: gfx::RenderTarget<ColorFormat> = "Target0",
224 });
225
226 // #1919
227 #[test]
228 fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
229     assert_eq!(
230         ::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>(),
231         8usize,
232         concat!(
233             "Size of template specialization: ",
234             stringify!(HandleWithDtor<::std::os::raw::c_int>)
235         )
236     );
237     assert_eq!(
238         ::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>(),
239         8usize,
240         concat!(
241             "Alignment of template specialization: ",
242             stringify!(HandleWithDtor<::std::os::raw::c_int>)
243         )
244     );
245 }
246
247 // #878
248 macro_rules! try_opt {
249     ($expr:expr) => (match $expr {
250         Some(val) => val,
251
252         None => { return None; }
253     })
254 }
255
256 // #2214
257 // macro call whose argument is an array with trailing comma.
258 fn issue2214() {
259     make_test!(
260         str_searcher_ascii_haystack,
261         "bb",
262         "abbcbbd",
263         [
264             Reject(0, 1),
265             Match(1, 3),
266             Reject(3, 4),
267             Match(4, 6),
268             Reject(6, 7),
269         ]
270     );
271 }
272
273 fn special_case_macros() {
274     let q = eprint!("{}", 1);
275     let r = eprint!(
276         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
277         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
278     );
279     let s = eprint!(
280         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
281         1,
282         2,
283         3,
284         4,
285         5,
286         6,
287         7,
288         8,
289         9,
290         10,
291         11,
292         12,
293         13,
294         14,
295         15,
296         16,
297         17,
298         18,
299         19,
300         20,
301         21,
302         22,
303         23,
304         24,
305         25,
306         26
307     );
308
309     let q = eprintln!("{}", 1);
310     let r = eprintln!(
311         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
312         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
313     );
314     let s = eprintln!(
315         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
316         1,
317         2,
318         3,
319         4,
320         5,
321         6,
322         7,
323         8,
324         9,
325         10,
326         11,
327         12,
328         13,
329         14,
330         15,
331         16,
332         17,
333         18,
334         19,
335         20,
336         21,
337         22,
338         23,
339         24,
340         25,
341         26
342     );
343
344     let q = format!("{}", 1);
345     let r = format!(
346         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
347         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
348     );
349     let s = format!(
350         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
351         1,
352         2,
353         3,
354         4,
355         5,
356         6,
357         7,
358         8,
359         9,
360         10,
361         11,
362         12,
363         13,
364         14,
365         15,
366         16,
367         17,
368         18,
369         19,
370         20,
371         21,
372         22,
373         23,
374         24,
375         25,
376         26
377     );
378
379     let q = format_args!("{}", 1);
380     let r = format_args!(
381         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
382         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
383     );
384     let s = format_args!(
385         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
386         1,
387         2,
388         3,
389         4,
390         5,
391         6,
392         7,
393         8,
394         9,
395         10,
396         11,
397         12,
398         13,
399         14,
400         15,
401         16,
402         17,
403         18,
404         19,
405         20,
406         21,
407         22,
408         23,
409         24,
410         25,
411         26
412     );
413
414     let q = print!("{}", 1);
415     let r = print!(
416         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
417         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
418     );
419     let s = print!(
420         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
421         1,
422         2,
423         3,
424         4,
425         5,
426         6,
427         7,
428         8,
429         9,
430         10,
431         11,
432         12,
433         13,
434         14,
435         15,
436         16,
437         17,
438         18,
439         19,
440         20,
441         21,
442         22,
443         23,
444         24,
445         25,
446         26
447     );
448
449     let q = println!("{}", 1);
450     let r = println!(
451         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
452         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
453     );
454     let s = println!(
455         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
456         1,
457         2,
458         3,
459         4,
460         5,
461         6,
462         7,
463         8,
464         9,
465         10,
466         11,
467         12,
468         13,
469         14,
470         15,
471         16,
472         17,
473         18,
474         19,
475         20,
476         21,
477         22,
478         23,
479         24,
480         25,
481         26
482     );
483
484     let q = unreachable!("{}", 1);
485     let r = unreachable!(
486         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
487         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
488     );
489     let s = unreachable!(
490         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
491         1,
492         2,
493         3,
494         4,
495         5,
496         6,
497         7,
498         8,
499         9,
500         10,
501         11,
502         12,
503         13,
504         14,
505         15,
506         16,
507         17,
508         18,
509         19,
510         20,
511         21,
512         22,
513         23,
514         24,
515         25,
516         26
517     );
518
519     debug!("{}", 1);
520     debug!(
521         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
522         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
523     );
524     debug!(
525         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
526         1,
527         2,
528         3,
529         4,
530         5,
531         6,
532         7,
533         8,
534         9,
535         10,
536         11,
537         12,
538         13,
539         14,
540         15,
541         16,
542         17,
543         18,
544         19,
545         20,
546         21,
547         22,
548         23,
549         24,
550         25,
551         26
552     );
553
554     error!("{}", 1);
555     error!(
556         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
557         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
558     );
559     error!(
560         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
561         1,
562         2,
563         3,
564         4,
565         5,
566         6,
567         7,
568         8,
569         9,
570         10,
571         11,
572         12,
573         13,
574         14,
575         15,
576         16,
577         17,
578         18,
579         19,
580         20,
581         21,
582         22,
583         23,
584         24,
585         25,
586         26
587     );
588
589     info!("{}", 1);
590     info!(
591         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
592         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
593     );
594     info!(
595         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
596         1,
597         2,
598         3,
599         4,
600         5,
601         6,
602         7,
603         8,
604         9,
605         10,
606         11,
607         12,
608         13,
609         14,
610         15,
611         16,
612         17,
613         18,
614         19,
615         20,
616         21,
617         22,
618         23,
619         24,
620         25,
621         26
622     );
623
624     panic!("{}", 1);
625     panic!(
626         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
627         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
628     );
629     panic!(
630         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
631         1,
632         2,
633         3,
634         4,
635         5,
636         6,
637         7,
638         8,
639         9,
640         10,
641         11,
642         12,
643         13,
644         14,
645         15,
646         16,
647         17,
648         18,
649         19,
650         20,
651         21,
652         22,
653         23,
654         24,
655         25,
656         26
657     );
658
659     warn!("{}", 1);
660     warn!(
661         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
662         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
663     );
664     warn!(
665         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
666         1,
667         2,
668         3,
669         4,
670         5,
671         6,
672         7,
673         8,
674         9,
675         10,
676         11,
677         12,
678         13,
679         14,
680         15,
681         16,
682         17,
683         18,
684         19,
685         20,
686         21,
687         22,
688         23,
689         24,
690         25,
691         26
692     );
693
694     assert!(result, "Ahoy there, {}!", target);
695     assert!(
696         result,
697         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
698         result, input, expected
699     );
700     assert!(
701         result,
702         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
703         1,
704         2,
705         3,
706         4,
707         5,
708         6,
709         7,
710         8,
711         9,
712         10,
713         11,
714         12,
715         13,
716         14,
717         15,
718         16,
719         17,
720         18,
721         19,
722         20,
723         21,
724         22,
725         23,
726         24,
727         25,
728         26
729     );
730
731     write!(&mut s, "Ahoy there, {}!", target);
732     write!(
733         &mut s,
734         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
735         result, input, expected
736     );
737     write!(
738         &mut s,
739         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
740         1,
741         2,
742         3,
743         4,
744         5,
745         6,
746         7,
747         8,
748         9,
749         10,
750         11,
751         12,
752         13,
753         14,
754         15,
755         16,
756         17,
757         18,
758         19,
759         20,
760         21,
761         22,
762         23,
763         24,
764         25,
765         26
766     );
767
768     writeln!(&mut s, "Ahoy there, {}!", target);
769     writeln!(
770         &mut s,
771         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
772         result, input, expected
773     );
774     writeln!(
775         &mut s,
776         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
777         1,
778         2,
779         3,
780         4,
781         5,
782         6,
783         7,
784         8,
785         9,
786         10,
787         11,
788         12,
789         13,
790         14,
791         15,
792         16,
793         17,
794         18,
795         19,
796         20,
797         21,
798         22,
799         23,
800         24,
801         25,
802         26
803     );
804 }
805
806 // #1209
807 impl Foo {
808     /// foo
809     pub fn foo(&self) -> Bar<foo!()> {}
810 }
811
812 // #819
813 fn macro_in_pattern_position() {
814     let x = match y {
815         foo!() => (),
816         bar!(a, b, c) => (),
817         bar!(a, b, c,) => (),
818         baz!(1 + 2 + 3, quux.kaas()) => (),
819         quux!(
820             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
821             BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
822         ) => (),
823     };
824 }