]> git.lizzy.rs Git - rust.git/blob - tests/target/macro_rules.rs
Update tests
[rust.git] / tests / target / macro_rules.rs
1 // rustfmt-error_on_line_overflow: false
2
3 macro_rules! m {
4     () => {};
5     ($x: ident) => {};
6     ($m1: ident, $m2: ident, $x: ident) => {};
7     ($($beginning: ident),*; $middle: ident; $($end: ident),*) => {};
8     (
9         $($beginning: ident),*;
10         $middle: ident;
11         $($end: ident),*;
12         $($beginning: ident),*;
13         $middle: ident;
14         $($end: ident),*
15     ) => {};
16     ($name: ident($($dol: tt $var: ident)*) $($body: tt)*) => {};
17 }
18
19 macro_rules! m {
20     // a
21     ($expr: expr, $($func: ident)*) => {{
22         let x = $expr;
23         $func(x)
24     }};
25
26     /* b */
27     () => {
28         /* c */
29     };
30
31     (@tag) => {};
32
33     // d
34     ($item: ident) => {
35         mod macro_item {
36             struct $item;
37         }
38     };
39 }
40
41 macro m2 {
42     // a
43     ($expr: expr, $($func: ident)*) => {{
44         let x = $expr;
45         $func(x)
46     }}
47
48     /* b */
49     () => {
50         /* c */
51     }
52
53     (@tag) => {}
54
55     // d
56     ($item: ident) => {
57         mod macro_item {
58             struct $item;
59         }
60     }
61 }
62
63 // #2438, #2476
64 macro_rules! m {
65     () => {
66         fn foo() {
67             this_line_is_98_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx();
68         }
69     };
70 }
71 macro_rules! m {
72     () => {
73         fn foo() {
74             this_line_is_99_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
75             );
76         }
77     };
78 }
79 macro_rules! m {
80     () => {
81         fn foo() {
82             this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
83             );
84         }
85     };
86 }
87 macro_rules! m {
88     () => {
89         fn foo() {
90             this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
91             );
92         }
93     };
94 }
95
96 // #2439
97 macro_rules! m {
98     (
99         $line0_xxxxxxxxxxxxxxxxx: expr,
100         $line1_xxxxxxxxxxxxxxxxx: expr,
101         $line2_xxxxxxxxxxxxxxxxx: expr,
102         $line3_xxxxxxxxxxxxxxxxx: expr,
103     ) => {};
104 }
105
106 // #2466
107 // Skip formatting `macro_rules!` that are not using `{}`.
108 macro_rules! m (
109     () => ()
110 );
111 macro_rules! m [
112     () => ()
113 ];
114
115 // #2470
116 macro foo($type_name: ident, $docs: expr) {
117     #[allow(non_camel_case_types)]
118     #[doc=$docs]
119     #[derive(Debug, Clone, Copy)]
120     pub struct $type_name;
121 }
122
123 // #2538
124 macro_rules! add_message_to_notes {
125     ($msg: expr) => {{
126         let mut lines = message.lines();
127         notes.push_str(&format!("\n{}: {}", level, lines.next().unwrap()));
128         for line in lines {
129             notes.push_str(&format!(
130                 "\n{:indent$}{line}",
131                 "",
132                 indent = level.len() + 2,
133                 line = line,
134             ));
135         }
136     }};
137 }