]> git.lizzy.rs Git - rust.git/blob - tests/target/macro_rules.rs
fix rewrite_string when a line feed is present in a sequence of whitespaces, resultin...
[rust.git] / tests / target / macro_rules.rs
1 macro_rules! m {
2     () => {};
3     ($x:ident) => {};
4     ($m1:ident, $m2:ident, $x:ident) => {};
5     ($($beginning:ident),*; $middle:ident; $($end:ident),*) => {};
6     (
7         $($beginning:ident),*;
8         $middle:ident;
9         $($end:ident),*;
10         $($beginning:ident),*;
11         $middle:ident;
12         $($end:ident),*
13     ) => {};
14     ($name:ident($($dol:tt $var:ident)*) $($body:tt)*) => {};
15     (
16         $($i:ident : $ty:ty, $def:expr, $stb:expr, $($dstring:tt),+);+ $(;)*
17         $($i:ident : $ty:ty, $def:expr, $stb:expr, $($dstring:tt),+);+ $(;)*
18     ) => {};
19     ($foo:tt foo[$attr:meta] $name:ident) => {};
20     ($foo:tt[$attr:meta] $name:ident) => {};
21     ($foo:tt &'a[$attr:meta] $name:ident) => {};
22     ($foo:tt foo #[$attr:meta] $name:ident) => {};
23     ($foo:tt #[$attr:meta] $name:ident) => {};
24     ($foo:tt &'a #[$attr:meta] $name:ident) => {};
25     ($x:tt foo bar foo bar foo bar $y:tt => x * y * z $z:tt, $($a:tt),*) => {};
26 }
27
28 macro_rules! impl_a_method {
29     ($n:ident($a:ident : $ta:ty) -> $ret:ty { $body:expr }) => {
30         fn $n($a: $ta) -> $ret {
31             $body
32         }
33         macro_rules! $n {
34             ($va: expr) => {
35                 $n($va)
36             };
37         }
38     };
39     ($n:ident($a:ident : $ta:ty, $b:ident : $tb:ty) -> $ret:ty { $body:expr }) => {
40         fn $n($a: $ta, $b: $tb) -> $ret {
41             $body
42         }
43         macro_rules! $n {
44             ($va: expr,$vb: expr) => {
45                 $n($va, $vb)
46             };
47         }
48     };
49     (
50         $n:ident($a:ident : $ta:ty, $b:ident : $tb:ty, $c:ident : $tc:ty) -> $ret:ty { $body:expr }
51     ) => {
52         fn $n($a: $ta, $b: $tb, $c: $tc) -> $ret {
53             $body
54         }
55         macro_rules! $n {
56             ($va: expr,$vb: expr,$vc: expr) => {
57                 $n($va, $vb, $vc)
58             };
59         }
60     };
61     (
62         $n:ident($a:ident : $ta:ty, $b:ident : $tb:ty, $c:ident : $tc:ty, $d:ident : $td:ty) ->
63         $ret:ty { $body:expr }
64     ) => {
65         fn $n($a: $ta, $b: $tb, $c: $tc, $d: $td) -> $ret {
66             $body
67         }
68         macro_rules! $n {
69             ($va: expr,$vb: expr,$vc: expr,$vd: expr) => {
70                 $n($va, $vb, $vc, $vd)
71             };
72         }
73     };
74 }
75
76 macro_rules! m {
77     // a
78     ($expr:expr, $($func:ident)*) => {{
79         let x = $expr;
80         $func(x)
81     }};
82
83     /* b */
84     () => {
85         /* c */
86     };
87
88     (@tag) => {};
89
90     // d
91     ($item:ident) => {
92         mod macro_item {
93             struct $item;
94         }
95     };
96 }
97
98 macro m2 {
99     // a
100     ($expr:expr, $($func:ident)*) => {{
101         let x = $expr;
102         $func(x)
103     }}
104
105     /* b */
106     () => {
107         /* c */
108     }
109
110     (@tag) => {}
111
112     // d
113     ($item:ident) => {
114         mod macro_item {
115             struct $item;
116         }
117     }
118 }
119
120 // #2438, #2476
121 macro_rules! m {
122     () => {
123         fn foo() {
124             this_line_is_98_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx();
125         }
126     };
127 }
128 macro_rules! m {
129     () => {
130         fn foo() {
131             this_line_is_99_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
132             );
133         }
134     };
135 }
136 macro_rules! m {
137     () => {
138         fn foo() {
139             this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
140             );
141         }
142     };
143 }
144 macro_rules! m {
145     () => {
146         fn foo() {
147             this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
148             );
149         }
150     };
151 }
152
153 // #2439
154 macro_rules! m {
155     (
156         $line0_xxxxxxxxxxxxxxxxx:expr,
157         $line1_xxxxxxxxxxxxxxxxx:expr,
158         $line2_xxxxxxxxxxxxxxxxx:expr,
159         $line3_xxxxxxxxxxxxxxxxx:expr,
160     ) => {};
161 }
162
163 // #2466
164 // Skip formatting `macro_rules!` that are not using `{}`.
165 macro_rules! m (
166     () => ()
167 );
168 macro_rules! m [
169     () => ()
170 ];
171
172 // #2470
173 macro foo($type_name:ident, $docs:expr) {
174     #[allow(non_camel_case_types)]
175     #[doc=$docs]
176     #[derive(Debug, Clone, Copy)]
177     pub struct $type_name;
178 }
179
180 // #2534
181 macro_rules! foo {
182     ($a:ident : $b:ty) => {};
183     ($a:ident $b:ident $c:ident) => {};
184 }
185
186 // #2538
187 macro_rules! add_message_to_notes {
188     ($msg:expr) => {{
189         let mut lines = message.lines();
190         notes.push_str(&format!("\n{}: {}", level, lines.next().unwrap()));
191         for line in lines {
192             notes.push_str(&format!(
193                 "\n{:indent$}{line}",
194                 "",
195                 indent = level.len() + 2,
196                 line = line,
197             ));
198         }
199     }};
200 }
201
202 // #2560
203 macro_rules! binary {
204     ($_self:ident, $expr:expr, $lhs:expr, $func:ident) => {
205         while $_self.matched($expr) {
206             let op = $_self.get_binary_op()?;
207
208             let rhs = Box::new($_self.$func()?);
209
210             $lhs = Spanned {
211                 span: $lhs.get_span().to(rhs.get_span()),
212                 value: Expression::Binary {
213                     lhs: Box::new($lhs),
214                     op,
215                     rhs,
216                 },
217             }
218         }
219     };
220 }
221
222 // #2558
223 macro_rules! m {
224     ($x:) => {};
225     ($($foo:expr)()?) => {};
226 }
227
228 // #2749
229 macro_rules! foo {
230     ($(x)* {}) => {};
231     ($(x)*()) => {};
232     ($(x)*[]) => {};
233 }
234 macro_rules! __wundergraph_expand_sqlite_mutation {
235     (
236         $mutation_name:ident $((context = $($context:tt)*))* {
237             $(
238                 $entity_name:ident(
239                     $(insert = $insert:ident,)*
240                     $(update = $update:ident,)*
241                     $(delete = $($delete:tt)+)*
242                 ),
243             )*
244         }
245     ) => {};
246 }
247
248 // #2607
249 macro_rules! bench {
250     ($ty:ident) => {
251         criterion_group!(
252             name = benches;
253             config = ::common_bench::reduced_samples();
254             targets = call, map;
255         );
256     };
257 }
258
259 // #2770
260 macro_rules! save_regs {
261     () => {
262         asm!("push rax
263               push rcx
264               push rdx
265               push rsi
266               push rdi
267               push r8
268               push r9
269               push r10
270               push r11"
271              :::: "intel", "volatile");
272     };
273 }
274
275 // #2721
276 macro_rules! impl_as_byte_slice_arrays {
277     ($n:expr,) => {};
278     ($n:expr, $N:ident, $($NN:ident,)*) => {
279         impl_as_byte_slice_arrays!($n - 1, $($NN,)*);
280
281         impl<T> AsByteSliceMut for [T; $n] where [T]: AsByteSliceMut {
282             fn as_byte_slice_mut(&mut self) -> &mut [u8] {
283                 self[..].as_byte_slice_mut()
284             }
285
286             fn to_le(&mut self) {
287                 self[..].to_le()
288             }
289         }
290     };
291     (!div $n:expr,) => {};
292     (!div $n:expr, $N:ident, $($NN:ident,)*) => {
293         impl_as_byte_slice_arrays!(!div $n / 2, $($NN,)*);
294
295         impl<T> AsByteSliceMut for [T; $n] where [T]: AsByteSliceMut {
296             fn as_byte_slice_mut(&mut self) -> &mut [u8] {
297                 self[..].as_byte_slice_mut()
298             }
299
300             fn to_le(&mut self) {
301                 self[..].to_le()
302             }
303         }
304     };
305 }