Skip to main content

hashbrown/
macros.rs

1// FIXME: remove once we bump MSRV >= 1.95.0
2// Originally by @folkertdev on Zulip:
3// https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/compiler-builtins.20msrv.20policy.3F/near/606320965
4/// Fallback `cfg_select!` on older Rust.
5///
6/// Requires braces around output, but works for items and expressions.
7#[cfg(not(feature = "nightly"))]
8#[macro_export]
9macro_rules! cfg_select {
10    ({ $($tt:tt)* }) => {{
11        $crate::cfg_select! { $($tt)* }
12    }};
13    (_ => { $($output:tt)* }) => {
14        $($output)*
15    };
16    (
17        $cfg:meta => $output:tt
18        $($( $rest:tt )+)?
19    ) => {
20        #[cfg($cfg)]
21        $crate::cfg_select! { _ => $output }
22        $(
23            #[cfg(not($cfg))]
24            $crate::cfg_select! { $($rest)+ }
25        )?
26    }
27}
28
29// Helper macro for specialization. This also helps avoid parse errors if the
30// default fn syntax for specialization changes in the future.
31#[cfg(feature = "nightly")]
32macro_rules! default_fn {
33    (#[$($a:tt)*] $($tt:tt)*) => {
34        #[$($a)*] default $($tt)*
35    }
36}
37#[cfg(not(feature = "nightly"))]
38macro_rules! default_fn {
39    ($($tt:tt)*) => {
40        $($tt)*
41    }
42}