]> git.lizzy.rs Git - rust.git/blob - src/libpanic_unwind/macros.rs
Auto merge of #51384 - QuietMisdreavus:extern-version, r=GuillaumeGomez
[rust.git] / src / libpanic_unwind / macros.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 /// A macro for defining `#[cfg]` if-else statements.
12 ///
13 /// This is similar to the `if/elif` C preprocessor macro by allowing definition
14 /// of a cascade of `#[cfg]` cases, emitting the implementation which matches
15 /// first.
16 ///
17 /// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code
18 /// without having to rewrite each clause multiple times.
19 macro_rules! cfg_if {
20     ($(
21         if #[cfg($($meta:meta),*)] { $($it:item)* }
22     ) else * else {
23         $($it2:item)*
24     }) => {
25         __cfg_if_items! {
26             () ;
27             $( ( ($($meta),*) ($($it)*) ), )*
28             ( () ($($it2)*) ),
29         }
30     }
31 }
32
33 macro_rules! __cfg_if_items {
34     (($($not:meta,)*) ; ) => {};
35     (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
36         __cfg_if_apply! { cfg(all(not(any($($not),*)), $($m,)*)), $($it)* }
37         __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* }
38     }
39 }
40
41 macro_rules! __cfg_if_apply {
42     ($m:meta, $($it:item)*) => {
43         $(#[$m] $it)*
44     }
45 }