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