]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
Merge pull request #2410 from topecongiro/skip-repeat-macro
[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 p = eprint!();
275     let q = eprint!("{}", 1);
276     let r = eprint!(
277         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
278         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
279     );
280     let s = eprint!(
281         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
282         1,
283         2,
284         3,
285         4,
286         5,
287         6,
288         7,
289         8,
290         9,
291         10,
292         11,
293         12,
294         13,
295         14,
296         15,
297         16,
298         17,
299         18,
300         19,
301         20,
302         21,
303         22,
304         23,
305         24,
306         25,
307         26
308     );
309
310     let q = eprintln!("{}", 1);
311     let r = eprintln!(
312         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
313         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
314     );
315     let s = eprintln!(
316         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
317         1,
318         2,
319         3,
320         4,
321         5,
322         6,
323         7,
324         8,
325         9,
326         10,
327         11,
328         12,
329         13,
330         14,
331         15,
332         16,
333         17,
334         18,
335         19,
336         20,
337         21,
338         22,
339         23,
340         24,
341         25,
342         26
343     );
344
345     let q = format!("{}", 1);
346     let r = format!(
347         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
348         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
349     );
350     let s = format!(
351         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
352         1,
353         2,
354         3,
355         4,
356         5,
357         6,
358         7,
359         8,
360         9,
361         10,
362         11,
363         12,
364         13,
365         14,
366         15,
367         16,
368         17,
369         18,
370         19,
371         20,
372         21,
373         22,
374         23,
375         24,
376         25,
377         26
378     );
379
380     let q = format_args!("{}", 1);
381     let r = format_args!(
382         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
383         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
384     );
385     let s = format_args!(
386         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
387         1,
388         2,
389         3,
390         4,
391         5,
392         6,
393         7,
394         8,
395         9,
396         10,
397         11,
398         12,
399         13,
400         14,
401         15,
402         16,
403         17,
404         18,
405         19,
406         20,
407         21,
408         22,
409         23,
410         24,
411         25,
412         26
413     );
414
415     let q = print!("{}", 1);
416     let r = print!(
417         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
418         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
419     );
420     let s = print!(
421         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
422         1,
423         2,
424         3,
425         4,
426         5,
427         6,
428         7,
429         8,
430         9,
431         10,
432         11,
433         12,
434         13,
435         14,
436         15,
437         16,
438         17,
439         18,
440         19,
441         20,
442         21,
443         22,
444         23,
445         24,
446         25,
447         26
448     );
449
450     let q = println!("{}", 1);
451     let r = println!(
452         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
453         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
454     );
455     let s = println!(
456         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
457         1,
458         2,
459         3,
460         4,
461         5,
462         6,
463         7,
464         8,
465         9,
466         10,
467         11,
468         12,
469         13,
470         14,
471         15,
472         16,
473         17,
474         18,
475         19,
476         20,
477         21,
478         22,
479         23,
480         24,
481         25,
482         26
483     );
484
485     let q = unreachable!("{}", 1);
486     let r = unreachable!(
487         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
488         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
489     );
490     let s = unreachable!(
491         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
492         1,
493         2,
494         3,
495         4,
496         5,
497         6,
498         7,
499         8,
500         9,
501         10,
502         11,
503         12,
504         13,
505         14,
506         15,
507         16,
508         17,
509         18,
510         19,
511         20,
512         21,
513         22,
514         23,
515         24,
516         25,
517         26
518     );
519
520     debug!("{}", 1);
521     debug!(
522         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
523         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
524     );
525     debug!(
526         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
527         1,
528         2,
529         3,
530         4,
531         5,
532         6,
533         7,
534         8,
535         9,
536         10,
537         11,
538         12,
539         13,
540         14,
541         15,
542         16,
543         17,
544         18,
545         19,
546         20,
547         21,
548         22,
549         23,
550         24,
551         25,
552         26
553     );
554
555     error!("{}", 1);
556     error!(
557         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
558         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
559     );
560     error!(
561         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
562         1,
563         2,
564         3,
565         4,
566         5,
567         6,
568         7,
569         8,
570         9,
571         10,
572         11,
573         12,
574         13,
575         14,
576         15,
577         16,
578         17,
579         18,
580         19,
581         20,
582         21,
583         22,
584         23,
585         24,
586         25,
587         26
588     );
589
590     info!("{}", 1);
591     info!(
592         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
593         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
594     );
595     info!(
596         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
597         1,
598         2,
599         3,
600         4,
601         5,
602         6,
603         7,
604         8,
605         9,
606         10,
607         11,
608         12,
609         13,
610         14,
611         15,
612         16,
613         17,
614         18,
615         19,
616         20,
617         21,
618         22,
619         23,
620         24,
621         25,
622         26
623     );
624
625     panic!("{}", 1);
626     panic!(
627         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
628         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
629     );
630     panic!(
631         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
632         1,
633         2,
634         3,
635         4,
636         5,
637         6,
638         7,
639         8,
640         9,
641         10,
642         11,
643         12,
644         13,
645         14,
646         15,
647         16,
648         17,
649         18,
650         19,
651         20,
652         21,
653         22,
654         23,
655         24,
656         25,
657         26
658     );
659
660     warn!("{}", 1);
661     warn!(
662         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
663         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
664     );
665     warn!(
666         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
667         1,
668         2,
669         3,
670         4,
671         5,
672         6,
673         7,
674         8,
675         9,
676         10,
677         11,
678         12,
679         13,
680         14,
681         15,
682         16,
683         17,
684         18,
685         19,
686         20,
687         21,
688         22,
689         23,
690         24,
691         25,
692         26
693     );
694
695     assert!();
696     assert!(result == 42);
697     assert!(result == 42, "Ahoy there, {}!", target);
698     assert!(
699         result == 42,
700         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
701         result,
702         input,
703         expected
704     );
705     assert!(
706         result == 42,
707         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
708         1,
709         2,
710         3,
711         4,
712         5,
713         6,
714         7,
715         8,
716         9,
717         10,
718         11,
719         12,
720         13,
721         14,
722         15,
723         16,
724         17,
725         18,
726         19,
727         20,
728         21,
729         22,
730         23,
731         24,
732         25,
733         26
734     );
735
736     assert_eq!();
737     assert_eq!(left);
738     assert_eq!(left, right);
739     assert_eq!(left, right, "Ahoy there, {}!", target);
740     assert_eq!(
741         left, right,
742         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
743         result, input, expected
744     );
745     assert_eq!(
746         first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line,
747         second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line,
748         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
749         result,
750         input,
751         expected
752     );
753     assert_eq!(
754         left + 42,
755         right,
756         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
757         result,
758         input,
759         expected
760     );
761     assert_eq!(
762         left,
763         right,
764         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
765         1,
766         2,
767         3,
768         4,
769         5,
770         6,
771         7,
772         8,
773         9,
774         10,
775         11,
776         12,
777         13,
778         14,
779         15,
780         16,
781         17,
782         18,
783         19,
784         20,
785         21,
786         22,
787         23,
788         24,
789         25,
790         26
791     );
792
793     write!(&mut s, "Ahoy there, {}!", target);
794     write!(
795         &mut s,
796         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
797         result, input, expected
798     );
799     write!(
800         &mut s,
801         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
802         1,
803         2,
804         3,
805         4,
806         5,
807         6,
808         7,
809         8,
810         9,
811         10,
812         11,
813         12,
814         13,
815         14,
816         15,
817         16,
818         17,
819         18,
820         19,
821         20,
822         21,
823         22,
824         23,
825         24,
826         25,
827         26
828     );
829
830     writeln!(&mut s, "Ahoy there, {}!", target);
831     writeln!(
832         &mut s,
833         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
834         result, input, expected
835     );
836     writeln!(
837         &mut s,
838         "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
839         1,
840         2,
841         3,
842         4,
843         5,
844         6,
845         7,
846         8,
847         9,
848         10,
849         11,
850         12,
851         13,
852         14,
853         15,
854         16,
855         17,
856         18,
857         19,
858         20,
859         21,
860         22,
861         23,
862         24,
863         25,
864         26
865     );
866 }
867
868 // #1209
869 impl Foo {
870     /// foo
871     pub fn foo(&self) -> Bar<foo!()> {}
872 }
873
874 // #819
875 fn macro_in_pattern_position() {
876     let x = match y {
877         foo!() => (),
878         bar!(a, b, c) => (),
879         bar!(a, b, c,) => (),
880         baz!(1 + 2 + 3, quux.kaas()) => (),
881         quux!(
882             AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
883             BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
884         ) => (),
885     };
886 }
887
888 macro foo() {
889
890 }
891
892 pub macro bar($x: ident + $y: expr;) {
893     fn foo($x: Foo) {
894         long_function(
895             a_long_argument_to_a_long_function_is_what_this_is(AAAAAAAAAAAAAAAAAAAAAAAAAAAA),
896             $x.bar($y),
897         );
898     }
899 }
900
901 macro foo() {
902     // a comment
903     fn foo() {
904         // another comment
905         bar();
906     }
907 }
908
909 macro lex_err($kind: ident $(, $body: expr)*) {
910     Err(QlError::LexError(LexError::$kind($($body,)*)))
911 }