about summary refs log tree commit diff
path: root/library/std/src/sys/pal/windows
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2025-08-10 14:25:43 -0700
committerJosh Triplett <josh@joshtriplett.org>2025-08-16 05:28:31 -0700
commit1ae4a0cc3487f28b29f36afe8056535afad21e7b (patch)
treea408ec3e10388ca37142ab6456a8ec7b83b141c6 /library/std/src/sys/pal/windows
parent3507a749b365aae4eefa96ab700a9315d3280ee7 (diff)
downloadrust-1ae4a0cc3487f28b29f36afe8056535afad21e7b.tar.gz
rust-1ae4a0cc3487f28b29f36afe8056535afad21e7b.zip
library: Migrate from `cfg_if` to `cfg_select`
Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
Diffstat (limited to 'library/std/src/sys/pal/windows')
-rw-r--r--library/std/src/sys/pal/windows/c.rs12
-rw-r--r--library/std/src/sys/pal/windows/mod.rs20
2 files changed, 17 insertions, 15 deletions
diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs
index edac5262a4e..25c1a82cc42 100644
--- a/library/std/src/sys/pal/windows/c.rs
+++ b/library/std/src/sys/pal/windows/c.rs
@@ -95,11 +95,8 @@ pub struct MOUNT_POINT_REPARSE_BUFFER {
 }
 
 // Desktop specific functions & types
-cfg_if::cfg_if! {
-if #[cfg(not(target_vendor = "uwp"))] {
-    pub const EXCEPTION_CONTINUE_SEARCH: i32 = 0;
-}
-}
+#[cfg(not(target_vendor = "uwp"))]
+pub const EXCEPTION_CONTINUE_SEARCH: i32 = 0;
 
 // Use raw-dylib to import ProcessPrng as we can't rely on there being an import library.
 #[cfg(not(target_vendor = "win7"))]
@@ -230,12 +227,13 @@ compat_fn_with_fallback! {
     }
 }
 
-cfg_if::cfg_if! {
-    if #[cfg(target_vendor = "uwp")] {
+cfg_select! {
+    target_vendor = "uwp" => {
         windows_targets::link_raw_dylib!("ntdll.dll" "system" fn NtCreateFile(filehandle : *mut HANDLE, desiredaccess : FILE_ACCESS_RIGHTS, objectattributes : *const OBJECT_ATTRIBUTES, iostatusblock : *mut IO_STATUS_BLOCK, allocationsize : *const i64, fileattributes : FILE_FLAGS_AND_ATTRIBUTES, shareaccess : FILE_SHARE_MODE, createdisposition : NTCREATEFILE_CREATE_DISPOSITION, createoptions : NTCREATEFILE_CREATE_OPTIONS, eabuffer : *const core::ffi::c_void, ealength : u32) -> NTSTATUS);
         windows_targets::link_raw_dylib!("ntdll.dll" "system" fn NtOpenFile(filehandle : *mut HANDLE, desiredaccess : u32, objectattributes : *const OBJECT_ATTRIBUTES, iostatusblock : *mut IO_STATUS_BLOCK, shareaccess : u32, openoptions : u32) -> NTSTATUS);
         windows_targets::link_raw_dylib!("ntdll.dll" "system" fn NtReadFile(filehandle : HANDLE, event : HANDLE, apcroutine : PIO_APC_ROUTINE, apccontext : *const core::ffi::c_void, iostatusblock : *mut IO_STATUS_BLOCK, buffer : *mut core::ffi::c_void, length : u32, byteoffset : *const i64, key : *const u32) -> NTSTATUS);
         windows_targets::link_raw_dylib!("ntdll.dll" "system" fn NtWriteFile(filehandle : HANDLE, event : HANDLE, apcroutine : PIO_APC_ROUTINE, apccontext : *const core::ffi::c_void, iostatusblock : *mut IO_STATUS_BLOCK, buffer : *const core::ffi::c_void, length : u32, byteoffset : *const i64, key : *const u32) -> NTSTATUS);
         windows_targets::link_raw_dylib!("ntdll.dll" "system" fn RtlNtStatusToDosError(status : NTSTATUS) -> u32);
     }
+    _ => {}
 }
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index 8f54e2376eb..10ad4541bed 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -22,10 +22,11 @@ pub mod os;
 pub mod pipe;
 pub mod thread;
 pub mod time;
-cfg_if::cfg_if! {
-    if #[cfg(not(target_vendor = "uwp"))] {
+cfg_select! {
+    not(target_vendor = "uwp") => {
         pub mod stack_overflow;
-    } else {
+    }
+    _ => {
         pub mod stack_overflow_uwp;
         pub use self::stack_overflow_uwp as stack_overflow;
     }
@@ -337,14 +338,17 @@ pub fn dur2timeout(dur: Duration) -> u32 {
 #[cfg(not(miri))] // inline assembly does not work in Miri
 pub fn abort_internal() -> ! {
     unsafe {
-        cfg_if::cfg_if! {
-            if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
+        cfg_select! {
+            any(target_arch = "x86", target_arch = "x86_64") => {
                 core::arch::asm!("int $$0x29", in("ecx") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
-            } else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
+            }
+            all(target_arch = "arm", target_feature = "thumb-mode") => {
                 core::arch::asm!(".inst 0xDEFB", in("r0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
-            } else if #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] {
+            }
+            any(target_arch = "aarch64", target_arch = "arm64ec") => {
                 core::arch::asm!("brk 0xF003", in("x0") c::FAST_FAIL_FATAL_APP_EXIT, options(noreturn, nostack));
-            } else {
+            }
+            _ => {
                 core::intrinsics::abort();
             }
         }