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