@@ -116,80 +116,3 @@ macro_rules! impl_fn_for_zst {
116
116
) +
117
117
}
118
118
}
119
-
120
- /// A macro for defining `#[cfg]` if-else statements.
121
- ///
122
- /// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade
123
- /// of `#[cfg]` cases, emitting the implementation which matches first.
124
- ///
125
- /// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code without having to
126
- /// rewrite each clause multiple times.
127
- ///
128
- /// # Example
129
- ///
130
- /// ```ignore(cannot-test-this-because-non-exported-macro)
131
- /// cfg_if! {
132
- /// if #[cfg(unix)] {
133
- /// fn foo() { /* unix specific functionality */ }
134
- /// } else if #[cfg(target_pointer_width = "32")] {
135
- /// fn foo() { /* non-unix, 32-bit functionality */ }
136
- /// } else {
137
- /// fn foo() { /* fallback implementation */ }
138
- /// }
139
- /// }
140
- ///
141
- /// # fn main() {}
142
- /// ```
143
- // This is a copy of `cfg_if!` from the `cfg_if` crate.
144
- // The recursive invocations should use $crate if this is ever exported.
145
- macro_rules! cfg_if {
146
- // match if/else chains with a final `else`
147
- (
148
- $(
149
- if #[ cfg( $i_meta: meta ) ] { $( $i_tokens: tt ) * }
150
- ) else+
151
- else { $( $e_tokens: tt ) * }
152
- ) => {
153
- cfg_if! {
154
- @__items ( ) ;
155
- $(
156
- ( ( $i_meta ) ( $( $i_tokens ) * ) ) ,
157
- ) +
158
- ( ( ) ( $( $e_tokens ) * ) ) ,
159
- }
160
- } ;
161
-
162
- // Internal and recursive macro to emit all the items
163
- //
164
- // Collects all the previous cfgs in a list at the beginning, so they can be
165
- // negated. After the semicolon is all the remaining items.
166
- ( @__items ( $( $_: meta , ) * ) ; ) => { } ;
167
- (
168
- @__items ( $( $no: meta , ) * ) ;
169
- ( ( $( $yes: meta ) ? ) ( $( $tokens: tt ) * ) ) ,
170
- $( $rest: tt , ) *
171
- ) => {
172
- // Emit all items within one block, applying an appropriate #[cfg]. The
173
- // #[cfg] will require all `$yes` matchers specified and must also negate
174
- // all previous matchers.
175
- #[ cfg( all(
176
- $( $yes , ) ?
177
- not( any( $( $no ) ,* ) )
178
- ) ) ]
179
- cfg_if! { @__identity $( $tokens ) * }
180
-
181
- // Recurse to emit all other items in `$rest`, and when we do so add all
182
- // our `$yes` matchers to the list of `$no` matchers as future emissions
183
- // will have to negate everything we just matched as well.
184
- cfg_if! {
185
- @__items ( $( $no , ) * $( $yes , ) ? ) ;
186
- $( $rest , ) *
187
- }
188
- } ;
189
-
190
- // Internal macro to make __apply work out right for different match types,
191
- // because of how macros match/expand stuff.
192
- ( @__identity $( $tokens: tt ) * ) => {
193
- $( $tokens ) *
194
- } ;
195
- }
0 commit comments