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