about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2025-04-15 06:42:39 -0700
committerThalia Archibald <thalia@archibald.dev>2025-04-18 19:49:23 -0700
commit670ff84d1c70146a2556b41650d3e417143c6c60 (patch)
treef0b7ab173ec3572bd84b2500215324bdc82f39bb
parent37712cc01604633fec6aac9bc720210207fa4b54 (diff)
downloadrust-670ff84d1c70146a2556b41650d3e417143c6c60.tar.gz
rust-670ff84d1c70146a2556b41650d3e417143c6c60.zip
Handle unsupported fallback
-rw-r--r--library/std/src/sys/env_consts.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/library/std/src/sys/env_consts.rs b/library/std/src/sys/env_consts.rs
index f439aa5a905..018d7954db2 100644
--- a/library/std/src/sys/env_consts.rs
+++ b/library/std/src/sys/env_consts.rs
@@ -1,6 +1,19 @@
 //! Constants associated with each target.
 
-// Keep entries sorted alphabetically.
+// Replaces the #[else] gate with #[cfg(not(any(…)))] of all the other gates.
+// This ensures that they must be mutually exclusive and do not have precedence
+// like cfg_if!.
+macro cfg_unordered(
+    $(#[cfg($cfg:meta)] $os:item)*
+    #[else] $fallback:item
+) {
+    $(#[cfg($cfg)] $os)*
+    #[cfg(not(any($($cfg),*)))] $fallback
+}
+
+// Keep entries sorted alphabetically and mutually exclusive.
+
+cfg_unordered! {
 
 #[cfg(target_os = "aix")]
 pub mod os {
@@ -375,3 +388,17 @@ pub mod os {
     pub const EXE_SUFFIX: &str = ".exe";
     pub const EXE_EXTENSION: &str = "exe";
 }
+
+// The fallback when none of the other gates match.
+#[else]
+pub mod os {
+    pub const FAMILY: &str = "";
+    pub const OS: &str = "";
+    pub const DLL_PREFIX: &str = "";
+    pub const DLL_SUFFIX: &str = "";
+    pub const DLL_EXTENSION: &str = "";
+    pub const EXE_SUFFIX: &str = "";
+    pub const EXE_EXTENSION: &str = "";
+}
+
+}