]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
fixup 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     ]).par_map_inplace(|el| *el = 0.);
177 }
178
179 fn issue_1885() {
180     let threads = people
181         .into_iter()
182         .map(|name| {
183             chan_select! {
184                 rx.recv() => {}
185             }
186         }).collect::<Vec<_>>();
187 }
188
189 fn issue_1917() {
190     mod x {
191         quickcheck! {
192             fn test(a: String, s: String, b: String) -> TestResult {
193                 if a.find(&s).is_none() {
194
195                     TestResult::from_bool(true)
196                 } else {
197                     TestResult::discard()
198                 }
199             }
200         }
201     }
202 }
203
204 fn issue_1921() {
205     // Macro with tabs.
206     lazy_static! {
207         static ref ONE: u32 = 1;
208         static ref TWO: u32 = 2;
209         static ref THREE: u32 = 3;
210         static ref FOUR: u32 = {
211             let mut acc = 1;
212             acc += 1;
213             acc += 2;
214             acc
215         };
216     }
217 }
218
219 // #1577
220 fn issue1577() {
221     let json = json!({
222         "foo": "bar",
223     });
224 }
225
226 gfx_pipeline!(pipe {
227     vbuf: gfx::VertexBuffer<Vertex> = (),
228     out: gfx::RenderTarget<ColorFormat> = "Target0",
229 });
230
231 // #1919
232 #[test]
233 fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
234     assert_eq!(
235         ::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>(),
236         8usize,
237         concat!(
238             "Size of template specialization: ",
239             stringify!(HandleWithDtor<::std::os::raw::c_int>)
240         )
241     );
242     assert_eq!(
243         ::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>(),
244         8usize,
245         concat!(
246             "Alignment of template specialization: ",
247             stringify!(HandleWithDtor<::std::os::raw::c_int>)
248         )
249     );
250 }
251
252 // #878
253 macro_rules! try_opt {
254     ($expr:expr) => {
255         match $expr {
256             Some(val) => val,
257
258             None => {
259                 return None;
260             }
261         }
262     };
263 }
264
265 // #2214
266 // macro call whose argument is an array with trailing comma.
267 fn issue2214() {
268     make_test!(
269         str_searcher_ascii_haystack,
270         "bb",
271         "abbcbbd",
272         [
273             Reject(0, 1),
274             Match(1, 3),
275             Reject(3, 4),
276             Match(4, 6),
277             Reject(6, 7),
278         ]
279     );
280 }
281
282 fn special_case_macros() {
283     let p = eprint!();
284     let q = eprint!("{}", 1);
285     let r = eprint!(
286         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
287         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
288     );
289     let s = eprint!(
290         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
291         1,
292         2,
293         3,
294         4,
295         5,
296         6,
297         7,
298         8,
299         9,
300         10,
301         11,
302         12,
303         13,
304         14,
305         15,
306         16,
307         17,
308         18,
309         19,
310         20,
311         21,
312         22,
313         23,
314         24,
315         25,
316         26
317     );
318
319     let q = eprintln!("{}", 1);
320     let r = eprintln!(
321         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
322         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
323     );
324     let s = eprintln!(
325         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
326         1,
327         2,
328         3,
329         4,
330         5,
331         6,
332         7,
333         8,
334         9,
335         10,
336         11,
337         12,
338         13,
339         14,
340         15,
341         16,
342         17,
343         18,
344         19,
345         20,
346         21,
347         22,
348         23,
349         24,
350         25,
351         26
352     );
353
354     let q = format!("{}", 1);
355     let r = format!(
356         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
357         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
358     );
359     let s = format!(
360         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
361         1,
362         2,
363         3,
364         4,
365         5,
366         6,
367         7,
368         8,
369         9,
370         10,
371         11,
372         12,
373         13,
374         14,
375         15,
376         16,
377         17,
378         18,
379         19,
380         20,
381         21,
382         22,
383         23,
384         24,
385         25,
386         26
387     );
388
389     let q = format_args!("{}", 1);
390     let r = format_args!(
391         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
392         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
393     );
394     let s = format_args!(
395         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
396         1,
397         2,
398         3,
399         4,
400         5,
401         6,
402         7,
403         8,
404         9,
405         10,
406         11,
407         12,
408         13,
409         14,
410         15,
411         16,
412         17,
413         18,
414         19,
415         20,
416         21,
417         22,
418         23,
419         24,
420         25,
421         26
422     );
423
424     let q = print!("{}", 1);
425     let r = print!(
426         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
427         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
428     );
429     let s = print!(
430         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
431         1,
432         2,
433         3,
434         4,
435         5,
436         6,
437         7,
438         8,
439         9,
440         10,
441         11,
442         12,
443         13,
444         14,
445         15,
446         16,
447         17,
448         18,
449         19,
450         20,
451         21,
452         22,
453         23,
454         24,
455         25,
456         26
457     );
458
459     let q = println!("{}", 1);
460     let r = println!(
461         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
462         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
463     );
464     let s = println!(
465         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
466         1,
467         2,
468         3,
469         4,
470         5,
471         6,
472         7,
473         8,
474         9,
475         10,
476         11,
477         12,
478         13,
479         14,
480         15,
481         16,
482         17,
483         18,
484         19,
485         20,
486         21,
487         22,
488         23,
489         24,
490         25,
491         26
492     );
493
494     let q = unreachable!("{}", 1);
495     let r = unreachable!(
496         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
497         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
498     );
499     let s = unreachable!(
500         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
501         1,
502         2,
503         3,
504         4,
505         5,
506         6,
507         7,
508         8,
509         9,
510         10,
511         11,
512         12,
513         13,
514         14,
515         15,
516         16,
517         17,
518         18,
519         19,
520         20,
521         21,
522         22,
523         23,
524         24,
525         25,
526         26
527     );
528
529     debug!("{}", 1);
530     debug!(
531         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
532         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
533     );
534     debug!(
535         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
536         1,
537         2,
538         3,
539         4,
540         5,
541         6,
542         7,
543         8,
544         9,
545         10,
546         11,
547         12,
548         13,
549         14,
550         15,
551         16,
552         17,
553         18,
554         19,
555         20,
556         21,
557         22,
558         23,
559         24,
560         25,
561         26
562     );
563
564     error!("{}", 1);
565     error!(
566         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
567         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
568     );
569     error!(
570         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
571         1,
572         2,
573         3,
574         4,
575         5,
576         6,
577         7,
578         8,
579         9,
580         10,
581         11,
582         12,
583         13,
584         14,
585         15,
586         16,
587         17,
588         18,
589         19,
590         20,
591         21,
592         22,
593         23,
594         24,
595         25,
596         26
597     );
598
599     info!("{}", 1);
600     info!(
601         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
602         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
603     );
604     info!(
605         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
606         1,
607         2,
608         3,
609         4,
610         5,
611         6,
612         7,
613         8,
614         9,
615         10,
616         11,
617         12,
618         13,
619         14,
620         15,
621         16,
622         17,
623         18,
624         19,
625         20,
626         21,
627         22,
628         23,
629         24,
630         25,
631         26
632     );
633
634     panic!("{}", 1);
635     panic!(
636         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
637         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
638     );
639     panic!(
640         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
641         1,
642         2,
643         3,
644         4,
645         5,
646         6,
647         7,
648         8,
649         9,
650         10,
651         11,
652         12,
653         13,
654         14,
655         15,
656         16,
657         17,
658         18,
659         19,
660         20,
661         21,
662         22,
663         23,
664         24,
665         25,
666         26
667     );
668
669     warn!("{}", 1);
670     warn!(
671         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
672         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
673     );
674     warn!(
675         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
676         1,
677         2,
678         3,
679         4,
680         5,
681         6,
682         7,
683         8,
684         9,
685         10,
686         11,
687         12,
688         13,
689         14,
690         15,
691         16,
692         17,
693         18,
694         19,
695         20,
696         21,
697         22,
698         23,
699         24,
700         25,
701         26
702     );
703
704     assert!();
705     assert!(result == 42);
706     assert!(result == 42, "Ahoy there, {}!", target);
707     assert!(
708         result == 42,
709         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
710         result,
711         input,
712         expected
713     );
714     assert!(
715         result == 42,
716         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
717         1,
718         2,
719         3,
720         4,
721         5,
722         6,
723         7,
724         8,
725         9,
726         10,
727         11,
728         12,
729         13,
730         14,
731         15,
732         16,
733         17,
734         18,
735         19,
736         20,
737         21,
738         22,
739         23,
740         24,
741         25,
742         26
743     );
744
745     assert_eq!();
746     assert_eq!(left);
747     assert_eq!(left, right);
748     assert_eq!(left, right, "Ahoy there, {}!", target);
749     assert_eq!(
750         left, right,
751         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
752         result, input, expected
753     );
754     assert_eq!(
755         first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line,
756         second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line,
757         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
758         result,
759         input,
760         expected
761     );
762     assert_eq!(
763         left + 42,
764         right,
765         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
766         result,
767         input,
768         expected
769     );
770     assert_eq!(
771         left,
772         right,
773         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
774         1,
775         2,
776         3,
777         4,
778         5,
779         6,
780         7,
781         8,
782         9,
783         10,
784         11,
785         12,
786         13,
787         14,
788         15,
789         16,
790         17,
791         18,
792         19,
793         20,
794         21,
795         22,
796         23,
797         24,
798         25,
799         26
800     );
801
802     write!(&mut s, "Ahoy there, {}!", target);
803     write!(
804         &mut s,
805         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
806         result, input, expected
807     );
808     write!(
809         &mut s,
810         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
811         1,
812         2,
813         3,
814         4,
815         5,
816         6,
817         7,
818         8,
819         9,
820         10,
821         11,
822         12,
823         13,
824         14,
825         15,
826         16,
827         17,
828         18,
829         19,
830         20,
831         21,
832         22,
833         23,
834         24,
835         25,
836         26
837     );
838
839     writeln!(&mut s, "Ahoy there, {}!", target);
840     writeln!(
841         &mut s,
842         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
843         result, input, expected
844     );
845     writeln!(
846         &mut s,
847         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
848         1,
849         2,
850         3,
851         4,
852         5,
853         6,
854         7,
855         8,
856         9,
857         10,
858         11,
859         12,
860         13,
861         14,
862         15,
863         16,
864         17,
865         18,
866         19,
867         20,
868         21,
869         22,
870         23,
871         24,
872         25,
873         26
874     );
875 }
876
877 // #1209
878 impl Foo {
879     /// foo
880     pub fn foo(&self) -> Bar<foo!()> {}
881 }
882
883 // #819
884 fn macro_in_pattern_position() {
885     let x = match y {
886         foo!() => (),
887         bar!(a, b, c) => (),
888         bar!(a, b, c,) => (),
889         baz!(1 + 2 + 3, quux.kaas()) => (),
890         quux!(
891             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
892             BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
893         ) => (),
894     };
895 }
896
897 macro foo() {}
898
899 pub macro bar($x:ident + $y:expr;) {
900     fn foo($x: Foo) {
901         long_function(
902             a_long_argument_to_a_long_function_is_what_this_is(AAAAAAAAAAAAAAAAAAAAAAAAAAAA),
903             $x.bar($y),
904         );
905     }
906 }
907
908 macro foo() {
909     // a comment
910     fn foo() {
911         // another comment
912         bar();
913     }
914 }
915
916 // #2574
917 macro_rules! test {
918     () => {{}};
919 }
920
921 macro lex_err($kind: ident $(, $body: expr)*) {
922     Err(QlError::LexError(LexError::$kind($($body,)*)))
923 }
924
925 // Preserve trailing comma on item-level macro with `()` or `[]`.
926 methods![get, post, delete,];
927 methods!(get, post, delete,);
928
929 // #2588
930 macro_rules! m {
931     () => {
932         r#"
933             test
934         "#
935     };
936 }
937 fn foo() {
938     f!{r#"
939             test
940        "#};
941 }
942
943 // #2591
944 fn foo() {
945     match 0u32 {
946         0 => (),
947         _ => unreachable!(/* obviously */),
948     }
949 }
950
951 fn foo() {
952     let _ = column!(/* here */);
953 }
954
955 // #2616
956 // Preserve trailing comma when using mixed layout for macro call.
957 fn foo() {
958     foo!(
959         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,
960         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
961     );
962     foo!(
963         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,
964         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,
965     );
966 }
967
968 // #2652
969 // Preserve trailing comma inside macro, even if it looks an array.
970 macro_rules! bar {
971     ($m:ident) => {
972         $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]);
973     };
974 }