Skip to content

Commit ea13aca

Browse files
committed
Handle unsupported fallback
1 parent 6305037 commit ea13aca

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Diff for: library/std/src/sys/env_consts.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
//! Constants associated with each target.
22
3+
// Collect all #[cfg(…)] gates, so that the #[else] fallback entry is
4+
// #[cfg(not(any(…)))] of all of them. This ensures that they are mutually
5+
// exclusive and do not have precedence like cfg_if!.
6+
macro_rules! cfg_unordered {
7+
([$($cfgs:meta,)*] #[cfg($cfg:meta)] $os:item $($rest:tt)*) => {
8+
#[cfg($cfg)] $os
9+
cfg_unordered!([$($cfgs,)* $cfg,] $($rest)*);
10+
};
11+
([$($cfgs:meta,)*] #[else] $last:item) => {
12+
#[cfg(not(any($($cfgs),*)))] $last
13+
};
14+
}
15+
316
// Keep entries sorted alphabetically.
417

18+
cfg_unordered! { []
19+
520
#[cfg(target_os = "aix")]
621
pub mod os {
722
pub const FAMILY: &str = "unix";
@@ -376,4 +391,16 @@ pub mod os {
376391
pub const EXE_EXTENSION: &str = "exe";
377392
}
378393

379-
// Keep entries sorted alphabetically.
394+
// Fallback when unsupported:
395+
#[else]
396+
pub mod os {
397+
pub const FAMILY: &str = "";
398+
pub const OS: &str = "";
399+
pub const DLL_PREFIX: &str = "";
400+
pub const DLL_SUFFIX: &str = "";
401+
pub const DLL_EXTENSION: &str = "";
402+
pub const EXE_SUFFIX: &str = "";
403+
pub const EXE_EXTENSION: &str = "";
404+
}
405+
406+
}

0 commit comments

Comments
 (0)