]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
Merge pull request #2330 from topecongiro/issue-2329
[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 == 42, "Ahoy there, {}!", target);
695     assert!(
696         result == 42,
697         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
698         result,
699         input,
700         expected
701     );
702     assert!(
703         result == 42,
704         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
705         1,
706         2,
707         3,
708         4,
709         5,
710         6,
711         7,
712         8,
713         9,
714         10,
715         11,
716         12,
717         13,
718         14,
719         15,
720         16,
721         17,
722         18,
723         19,
724         20,
725         21,
726         22,
727         23,
728         24,
729         25,
730         26
731     );
732
733     assert_eq!(left, right, "Ahoy there, {}!", target);
734     assert_eq!(
735         left, right,
736         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
737         result, input, expected
738     );
739     assert_eq!(
740         first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line,
741         second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line,
742         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
743         result,
744         input,
745         expected
746     );
747     assert_eq!(
748         left + 42,
749         right,
750         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
751         result,
752         input,
753         expected
754     );
755     assert_eq!(
756         left,
757         right,
758         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
759         1,
760         2,
761         3,
762         4,
763         5,
764         6,
765         7,
766         8,
767         9,
768         10,
769         11,
770         12,
771         13,
772         14,
773         15,
774         16,
775         17,
776         18,
777         19,
778         20,
779         21,
780         22,
781         23,
782         24,
783         25,
784         26
785     );
786
787     write!(&mut s, "Ahoy there, {}!", target);
788     write!(
789         &mut s,
790         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
791         result, input, expected
792     );
793     write!(
794         &mut s,
795         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
796         1,
797         2,
798         3,
799         4,
800         5,
801         6,
802         7,
803         8,
804         9,
805         10,
806         11,
807         12,
808         13,
809         14,
810         15,
811         16,
812         17,
813         18,
814         19,
815         20,
816         21,
817         22,
818         23,
819         24,
820         25,
821         26
822     );
823
824     writeln!(&mut s, "Ahoy there, {}!", target);
825     writeln!(
826         &mut s,
827         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
828         result, input, expected
829     );
830     writeln!(
831         &mut s,
832         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
833         1,
834         2,
835         3,
836         4,
837         5,
838         6,
839         7,
840         8,
841         9,
842         10,
843         11,
844         12,
845         13,
846         14,
847         15,
848         16,
849         17,
850         18,
851         19,
852         20,
853         21,
854         22,
855         23,
856         24,
857         25,
858         26
859     );
860 }
861
862 // #1209
863 impl Foo {
864     /// foo
865     pub fn foo(&self) -> Bar<foo!()> {}
866 }
867
868 // #819
869 fn macro_in_pattern_position() {
870     let x = match y {
871         foo!() => (),
872         bar!(a, b, c) => (),
873         bar!(a, b, c,) => (),
874         baz!(1 + 2 + 3, quux.kaas()) => (),
875         quux!(
876             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
877             BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
878         ) => (),
879     };
880 }
881
882 macro foo() {
883
884 }
885
886 pub macro bar($x: ident + $y: expr;) {
887     fn foo($x: Foo) {
888         long_function(
889             a_long_argument_to_a_long_function_is_what_this_is(AAAAAAAAAAAAAAAAAAAAAAAAAAAA),
890             $x.bar($y),
891         );
892     }
893 }
894
895 macro foo() {
896     // a comment
897     fn foo() {
898         // another comment
899         bar();
900     }
901 }