@@ -117,84 +117,3 @@ macro_rules! impl_fn_for_zst {
117
117
) +
118
118
}
119
119
}
120
-
121
- /// A macro for defining `#[cfg]` if-else statements.
122
- ///
123
- /// The macro provided by this crate, `cfg_if`, is similar to the `if/elif` C
124
- /// preprocessor macro by allowing definition of a cascade of `#[cfg]` cases,
125
- /// emitting the implementation which matches first.
126
- ///
127
- /// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
128
- /// without having to rewrite each clause multiple times.
129
- ///
130
- /// # Example
131
- ///
132
- /// ```
133
- /// #[macro_use]
134
- /// extern crate cfg_if;
135
- ///
136
- /// cfg_if! {
137
- /// if #[cfg(unix)] {
138
- /// fn foo() { /* unix specific functionality */ }
139
- /// } else if #[cfg(target_pointer_width = "32")] {
140
- /// fn foo() { /* non-unix, 32-bit functionality */ }
141
- /// } else {
142
- /// fn foo() { /* fallback implementation */ }
143
- /// }
144
- /// }
145
- ///
146
- /// # fn main() {}
147
- /// ```
148
- macro_rules! cfg_if {
149
- // match if/else chains with a final `else`
150
- ( $(
151
- if #[ cfg( $( $meta: meta) ,* ) ] { $( $it: item) * }
152
- ) else * else {
153
- $( $it2: item) *
154
- } ) => {
155
- cfg_if! {
156
- @__items
157
- ( ) ;
158
- $( ( ( $( $meta) ,* ) ( $( $it) * ) ) , ) *
159
- ( ( ) ( $( $it2) * ) ) ,
160
- }
161
- } ;
162
-
163
- // match if/else chains lacking a final `else`
164
- (
165
- if #[ cfg( $( $i_met: meta) ,* ) ] { $( $i_it: item) * }
166
- $(
167
- else if #[ cfg( $( $e_met: meta) ,* ) ] { $( $e_it: item) * }
168
- ) *
169
- ) => {
170
- cfg_if! {
171
- @__items
172
- ( ) ;
173
- ( ( $( $i_met) ,* ) ( $( $i_it) * ) ) ,
174
- $( ( ( $( $e_met) ,* ) ( $( $e_it) * ) ) , ) *
175
- ( ( ) ( ) ) ,
176
- }
177
- } ;
178
-
179
- // Internal and recursive macro to emit all the items
180
- //
181
- // Collects all the negated cfgs in a list at the beginning and after the
182
- // semicolon is all the remaining items
183
- ( @__items ( $( $not: meta, ) * ) ; ) => { } ;
184
- ( @__items ( $( $not: meta, ) * ) ; ( ( $( $m: meta) ,* ) ( $( $it: item) * ) ) , $( $rest: tt) * ) => {
185
- // Emit all items within one block, applying an approprate #[cfg]. The
186
- // #[cfg] will require all `$m` matchers specified and must also negate
187
- // all previous matchers.
188
- cfg_if! { @__apply cfg( all( $( $m, ) * not( any( $( $not) ,* ) ) ) ) , $( $it) * }
189
-
190
- // Recurse to emit all other items in `$rest`, and when we do so add all
191
- // our `$m` matchers to the list of `$not` matchers as future emissions
192
- // will have to negate everything we just matched as well.
193
- cfg_if! { @__items ( $( $not, ) * $( $m, ) * ) ; $( $rest) * }
194
- } ;
195
-
196
- // Internal macro to Apply a cfg attribute to a list of items
197
- ( @__apply $m: meta, $( $it: item) * ) => {
198
- $( #[ $m] $it) *
199
- } ;
200
- }
0 commit comments