]> git.proxmox.com Git - rustc.git/blame - src/vendor/libc/src/macros.rs
New upstream version 1.30.0~beta.7+dfsg1
[rustc.git] / src / vendor / libc / src / macros.rs
CommitLineData
476ff2be
SL
1/// A macro for defining #[cfg] if-else statements.
2///
3/// This is similar to the `if/elif` C preprocessor macro by allowing definition
4/// of a cascade of `#[cfg]` cases, emitting the implementation which matches
5/// first.
6///
7/// This allows you to conveniently provide a long list #[cfg]'d blocks of code
8/// without having to rewrite each clause multiple times.
9macro_rules! cfg_if {
10 ($(
11 if #[cfg($($meta:meta),*)] { $($it:item)* }
12 ) else * else {
13 $($it2:item)*
14 }) => {
15 __cfg_if_items! {
16 () ;
17 $( ( ($($meta),*) ($($it)*) ), )*
18 ( () ($($it2)*) ),
19 }
20 }
21}
22
23macro_rules! __cfg_if_items {
24 (($($not:meta,)*) ; ) => {};
25 (($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
26 __cfg_if_apply! { cfg(all(not(any($($not),*)), $($m,)*)), $($it)* }
27 __cfg_if_items! { ($($not,)* $($m,)*) ; $($rest)* }
28 }
29}
30
31macro_rules! __cfg_if_apply {
32 ($m:meta, $($it:item)*) => {
33 $(#[$m] $it)*
34 }
35}
36
37macro_rules! s {
b7449926 38 ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
476ff2be
SL
39 __item! {
40 #[repr(C)]
41 $(#[$attr])*
b7449926 42 pub $t $i { $($field)* }
476ff2be
SL
43 }
44 impl ::dox::Copy for $i {}
45 impl ::dox::Clone for $i {
46 fn clone(&self) -> $i { *self }
47 }
48 )*)
49}
50
51macro_rules! f {
52 ($(pub fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
53 $($body:stmt);*
54 })*) => ($(
55 #[inline]
0531ce1d 56 #[cfg(not(cross_platform_docs))]
476ff2be
SL
57 pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
58 $($body);*
59 }
60
0531ce1d 61 #[cfg(cross_platform_docs)]
476ff2be
SL
62 #[allow(dead_code)]
63 pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
64 loop {}
65 }
66 )*)
67}
68
69macro_rules! __item {
70 ($i:item) => ($i)
71}
b7449926
XL
72
73#[allow(unused_macros)]
74macro_rules! align_const {
75 ($($(#[$attr:meta])* pub const $name:ident : $t1:ty = $t2:ident { $($field:tt)* };)*) => ($(
76 #[cfg(feature = "align")]
77 $(#[$attr])*
78 pub const $name : $t1 = $t2 {
79 $($field)*
80 };
81 #[cfg(not(feature = "align"))]
82 $(#[$attr])*
83 pub const $name : $t1 = $t2 {
84 $($field)*
85 __align: [],
86 };
87 )*)
88}