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