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