From ecfc419144a6e54d84d2953c21fe6d9f8542f136 Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 2 Oct 2023 11:00:13 -0300 Subject: [PATCH] Initiate the inner usage of cfg_match (Library) --- Cargo.lock | 1 - library/core/src/ffi/mod.rs | 23 +++--- library/core/src/internal_macros.rs | 77 ------------------- library/core/src/lib.rs | 1 + library/panic_abort/src/lib.rs | 22 +++--- library/panic_unwind/src/lib.rs | 29 ++++--- library/panic_unwind/src/seh.rs | 7 +- library/std/src/lib.rs | 1 + library/std/src/os/unix/process.rs | 12 +-- .../std/src/sys/common/thread_local/mod.rs | 10 ++- library/std/src/sys/mod.rs | 45 +++++++---- library/std/src/sys/personality/gcc.rs | 14 ++-- library/std/src/sys/personality/mod.rs | 15 ++-- library/std/src/sys/unix/alloc.rs | 12 +-- library/std/src/sys/unix/locks/mod.rs | 12 +-- library/std/src/sys/unix/mod.rs | 34 +++++--- library/std/src/sys/unix/os.rs | 7 +- library/std/src/sys/unix/process/mod.rs | 13 ++-- .../src/sys/unix/process/process_common.rs | 20 +++-- .../std/src/sys/unix/process/process_unix.rs | 5 +- .../std/src/sys/unix/thread_parking/mod.rs | 12 +-- library/std/src/sys/wasi/mod.rs | 7 +- library/std/src/sys/wasi/os.rs | 7 +- library/std/src/sys/wasi/thread.rs | 21 ++--- library/std/src/sys/wasm/mod.rs | 7 +- library/std/src/sys/windows/c.rs | 50 ++++++------ library/std/src/sys/windows/mod.rs | 7 +- library/std/src/sys_common/mod.rs | 16 ++-- library/std/src/sys_common/net.rs | 28 ++++--- library/std/src/sys_common/once/mod.rs | 14 ++-- .../std/src/sys_common/thread_parking/mod.rs | 14 ++-- library/unwind/Cargo.toml | 1 - library/unwind/src/lib.rs | 51 +++++++----- library/unwind/src/libunwind.rs | 19 ++--- 34 files changed, 310 insertions(+), 304 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f91d12a419c1..65d0a670db2b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5836,7 +5836,6 @@ name = "unwind" version = "0.0.0" dependencies = [ "cc", - "cfg-if", "compiler_builtins", "core", "libc", diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index b2c9a0800c91b..094cf7d51d1c9 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -97,9 +97,9 @@ pub type c_ptrdiff_t = isize; pub type c_ssize_t = isize; mod c_char_definition { - cfg_if! { + cfg_match! { // These are the targets on which c_char is unsigned. - if #[cfg(any( + cfg(any( all( target_os = "linux", any( @@ -150,10 +150,11 @@ mod c_char_definition { ), all(target_os = "nto", target_arch = "aarch64"), target_os = "horizon" - ))] { + )) => { pub type c_char = u8; pub type NonZero_c_char = crate::num::NonZeroU8; - } else { + } + _ => { // On every other target, c_char is signed. pub type c_char = i8; pub type NonZero_c_char = crate::num::NonZeroI8; @@ -162,13 +163,14 @@ mod c_char_definition { } mod c_int_definition { - cfg_if! { - if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] { + cfg_match! { + cfg(any(target_arch = "avr", target_arch = "msp430")) => { pub type c_int = i16; pub type NonZero_c_int = crate::num::NonZeroI16; pub type c_uint = u16; pub type NonZero_c_uint = crate::num::NonZeroU16; - } else { + } + _ => { pub type c_int = i32; pub type NonZero_c_int = crate::num::NonZeroI32; pub type c_uint = u32; @@ -178,13 +180,14 @@ mod c_int_definition { } mod c_long_definition { - cfg_if! { - if #[cfg(all(target_pointer_width = "64", not(windows)))] { + cfg_match! { + cfg(all(target_pointer_width = "64", not(windows))) => { pub type c_long = i64; pub type NonZero_c_long = crate::num::NonZeroI64; pub type c_ulong = u64; pub type NonZero_c_ulong = crate::num::NonZeroU64; - } else { + } + _ =>{ // The minimal size of `long` in the C standard is 32 bits pub type c_long = i32; pub type NonZero_c_long = crate::num::NonZeroI32; diff --git a/library/core/src/internal_macros.rs b/library/core/src/internal_macros.rs index 5774107f5207f..be12f90464084 100644 --- a/library/core/src/internal_macros.rs +++ b/library/core/src/internal_macros.rs @@ -116,80 +116,3 @@ macro_rules! impl_fn_for_zst { )+ } } - -/// A macro for defining `#[cfg]` if-else statements. -/// -/// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade -/// of `#[cfg]` cases, emitting the implementation which matches first. -/// -/// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code without having to -/// rewrite each clause multiple times. -/// -/// # Example -/// -/// ```ignore(cannot-test-this-because-non-exported-macro) -/// cfg_if! { -/// if #[cfg(unix)] { -/// fn foo() { /* unix specific functionality */ } -/// } else if #[cfg(target_pointer_width = "32")] { -/// fn foo() { /* non-unix, 32-bit functionality */ } -/// } else { -/// fn foo() { /* fallback implementation */ } -/// } -/// } -/// -/// # fn main() {} -/// ``` -// This is a copy of `cfg_if!` from the `cfg_if` crate. -// The recursive invocations should use $crate if this is ever exported. -macro_rules! cfg_if { - // match if/else chains with a final `else` - ( - $( - if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* } - ) else+ - else { $( $e_tokens:tt )* } - ) => { - cfg_if! { - @__items () ; - $( - (( $i_meta ) ( $( $i_tokens )* )) , - )+ - (() ( $( $e_tokens )* )) , - } - }; - - // Internal and recursive macro to emit all the items - // - // Collects all the previous cfgs in a list at the beginning, so they can be - // negated. After the semicolon is all the remaining items. - (@__items ( $( $_:meta , )* ) ; ) => {}; - ( - @__items ( $( $no:meta , )* ) ; - (( $( $yes:meta )? ) ( $( $tokens:tt )* )) , - $( $rest:tt , )* - ) => { - // Emit all items within one block, applying an appropriate #[cfg]. The - // #[cfg] will require all `$yes` matchers specified and must also negate - // all previous matchers. - #[cfg(all( - $( $yes , )? - not(any( $( $no ),* )) - ))] - cfg_if! { @__identity $( $tokens )* } - - // Recurse to emit all other items in `$rest`, and when we do so add all - // our `$yes` matchers to the list of `$no` matchers as future emissions - // will have to negate everything we just matched as well. - cfg_if! { - @__items ( $( $no , )* $( $yes , )? ) ; - $( $rest , )* - } - }; - - // Internal macro to make __apply work out right for different match types, - // because of how macros match/expand stuff. - (@__identity $( $tokens:tt )* ) => { - $( $tokens )* - }; -} diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index be734a9ba5298..06a23932bfe56 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -112,6 +112,7 @@ // tidy-alphabetical-start #![cfg_attr(bootstrap, feature(no_coverage))] // rust-lang/rust#84605 #![cfg_attr(not(bootstrap), feature(coverage_attribute))] // rust-lang/rust#84605 +#![feature(cfg_match)] #![feature(char_indices_offset)] #![feature(const_align_of_val)] #![feature(const_align_of_val_raw)] diff --git a/library/panic_abort/src/lib.rs b/library/panic_abort/src/lib.rs index 6e097e2caf24b..5c16ae49325f4 100644 --- a/library/panic_abort/src/lib.rs +++ b/library/panic_abort/src/lib.rs @@ -8,6 +8,7 @@ #![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")] #![panic_runtime] #![allow(unused_features)] +#![feature(cfg_match)] #![feature(core_intrinsics)] #![feature(panic_runtime)] #![feature(std_internals)] @@ -37,16 +38,17 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 { abort(); - cfg_if::cfg_if! { - if #[cfg(any(unix, target_os = "solid_asp3"))] { + cfg_match! { + cfg(any(unix, target_os = "solid_asp3")) => { unsafe fn abort() -> ! { libc::abort(); } - } else if #[cfg(any(target_os = "hermit", - all(target_vendor = "fortanix", target_env = "sgx"), - target_os = "xous", - target_os = "uefi", - ))] { + } + cfg(any(target_os = "hermit", + all(target_vendor = "fortanix", target_env = "sgx"), + target_os = "xous", + target_os = "uefi", + )) => { unsafe fn abort() -> ! { // call std::sys::abort_internal extern "C" { @@ -54,7 +56,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 { } __rust_abort(); } - } else if #[cfg(all(windows, not(miri)))] { + } + cfg(all(windows, not(miri))) => { // On Windows, use the processor-specific __fastfail mechanism. In Windows 8 // and later, this will terminate the process immediately without running any // in-process exception handlers. In earlier versions of Windows, this @@ -81,7 +84,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 { } core::intrinsics::unreachable(); } - } else { + } + _ => { unsafe fn abort() -> ! { core::intrinsics::abort(); } diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 9363fde5de2e7..18597db279c67 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -14,6 +14,7 @@ #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] #![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")] +#![feature(cfg_match)] #![feature(core_intrinsics)] #![feature(lang_items)] #![feature(panic_unwind)] @@ -31,31 +32,36 @@ use alloc::boxed::Box; use core::any::Any; use core::panic::PanicPayload; -cfg_if::cfg_if! { - if #[cfg(target_os = "emscripten")] { +cfg_match! { + cfg(target_os = "emscripten") => { #[path = "emcc.rs"] mod real_imp; - } else if #[cfg(target_os = "hermit")] { + } + cfg(target_os = "hermit") => { #[path = "hermit.rs"] mod real_imp; - } else if #[cfg(target_os = "l4re")] { + } + cfg(target_os = "l4re") => { // L4Re is unix family but does not yet support unwinding. #[path = "dummy.rs"] mod real_imp; - } else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] { + } + cfg(all(target_env = "msvc", not(target_arch = "arm"))) => { // LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc) #[path = "seh.rs"] mod real_imp; - } else if #[cfg(any( + } + cfg(any( all(target_family = "windows", target_env = "gnu"), target_os = "psp", target_os = "solid_asp3", all(target_family = "unix", not(target_os = "espidf")), all(target_vendor = "fortanix", target_env = "sgx"), - ))] { + )) => { #[path = "gcc.rs"] mod real_imp; - } else { + } + _ => { // Targets that don't support unwinding. // - family=wasm // - os=none ("bare metal" targets) @@ -68,14 +74,15 @@ cfg_if::cfg_if! { } } -cfg_if::cfg_if! { - if #[cfg(miri)] { +cfg_match! { + cfg(miri) => { // Use the Miri runtime. // We still need to also load the normal runtime above, as rustc expects certain lang // items from there to be defined. #[path = "miri.rs"] mod imp; - } else { + } + _ => { // Use the real runtime. use real_imp as imp; } diff --git a/library/panic_unwind/src/seh.rs b/library/panic_unwind/src/seh.rs index 99db00e549066..b3a85553fda59 100644 --- a/library/panic_unwind/src/seh.rs +++ b/library/panic_unwind/src/seh.rs @@ -253,10 +253,11 @@ macro_rules! define_cleanup { } } } -cfg_if::cfg_if! { - if #[cfg(target_arch = "x86")] { +cfg_match! { + cfg(target_arch = "x86") => { define_cleanup!("thiscall" "thiscall-unwind"); - } else { + } + _ => { define_cleanup!("C" "C-unwind"); } } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 6f78778f01a54..dbf36589d04b0 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -305,6 +305,7 @@ // // Library features (core): // tidy-alphabetical-start +#![feature(cfg_match)] #![feature(char_internals)] #![feature(core_intrinsics)] #![feature(duration_constants)] diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 5d9f7430ca2cb..34eac9b7803c1 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -12,19 +12,19 @@ use crate::sealed::Sealed; use crate::sys; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; -use cfg_if::cfg_if; - -cfg_if! { - if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] { +cfg_match! { + cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita")) => { type UserId = u16; type GroupId = u16; - } else if #[cfg(target_os = "nto")] { + } + cfg(target_os = "nto") => { // Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP. // Only positive values should be used, see e.g. // https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html type UserId = i32; type GroupId = i32; - } else { + } + _ => { type UserId = u32; type GroupId = u32; } diff --git a/library/std/src/sys/common/thread_local/mod.rs b/library/std/src/sys/common/thread_local/mod.rs index 8b2c839f837d4..b33ac8618d26f 100644 --- a/library/std/src/sys/common/thread_local/mod.rs +++ b/library/std/src/sys/common/thread_local/mod.rs @@ -5,18 +5,20 @@ // "fast" key type is accessed via code generated via LLVM, where TLS keys are set up by the linker. // "static" is for single-threaded platforms where a global static is sufficient. -cfg_if::cfg_if! { - if #[cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi"))] { +cfg_match! { + cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi")) => { #[doc(hidden)] mod static_local; #[doc(hidden)] pub use static_local::{Key, thread_local_inner}; - } else if #[cfg(target_thread_local)] { + } + cfg(target_thread_local) => { #[doc(hidden)] mod fast_local; #[doc(hidden)] pub use fast_local::{Key, thread_local_inner}; - } else { + } + _ => { #[doc(hidden)] mod os_local; #[doc(hidden)] diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index 159ffe7ac9635..55c3494c57e71 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -25,55 +25,66 @@ pub mod common; mod personality; -cfg_if::cfg_if! { - if #[cfg(unix)] { +cfg_match! { + cfg(unix) => { mod unix; pub use self::unix::*; - } else if #[cfg(windows)] { + } + cfg(windows) => { mod windows; pub use self::windows::*; - } else if #[cfg(target_os = "solid_asp3")] { + } + cfg(target_os = "solid_asp3") => { mod solid; pub use self::solid::*; - } else if #[cfg(target_os = "hermit")] { + } + cfg(target_os = "hermit") => { mod hermit; pub use self::hermit::*; - } else if #[cfg(target_os = "wasi")] { + } + cfg(target_os = "wasi") => { mod wasi; pub use self::wasi::*; - } else if #[cfg(target_family = "wasm")] { + } + cfg(target_family = "wasm") => { mod wasm; pub use self::wasm::*; - } else if #[cfg(target_os = "xous")] { + } + cfg(target_os = "xous") => { mod xous; pub use self::xous::*; - } else if #[cfg(target_os = "uefi")] { + } + cfg(target_os = "uefi") => { mod uefi; pub use self::uefi::*; - } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] { + } + cfg(all(target_vendor = "fortanix", target_env = "sgx")) => { mod sgx; pub use self::sgx::*; - } else { + } + _ => { mod unsupported; pub use self::unsupported::*; } } -cfg_if::cfg_if! { +cfg_match! { // Fuchsia components default to full backtrace. - if #[cfg(target_os = "fuchsia")] { + cfg(target_os = "fuchsia") => { pub const FULL_BACKTRACE_DEFAULT: bool = true; - } else { + } + _ => { pub const FULL_BACKTRACE_DEFAULT: bool = false; } } #[cfg(not(test))] -cfg_if::cfg_if! { - if #[cfg(target_os = "android")] { +cfg_match! { + cfg(target_os = "android") => { pub use self::android::log2f32; pub use self::android::log2f64; - } else { + } + _ => { #[inline] pub fn log2f32(n: f32) -> f32 { unsafe { crate::intrinsics::log2f32(n) } diff --git a/library/std/src/sys/personality/gcc.rs b/library/std/src/sys/personality/gcc.rs index e477a0cd7ab81..0f8545a35ff64 100644 --- a/library/std/src/sys/personality/gcc.rs +++ b/library/std/src/sys/personality/gcc.rs @@ -92,8 +92,8 @@ const UNWIND_DATA_REG: (i32, i32) = (4, 5); // a0, a1 // https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc // https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c -cfg_if::cfg_if! { - if #[cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "tvos"), not(target_os = "watchos"), not(target_os = "netbsd")))] { +cfg_match! { + cfg(all(target_arch = "arm", not(target_os = "ios"), not(target_os = "tvos"), not(target_os = "watchos"), not(target_os = "netbsd"))) => { // ARM EHABI personality routine. // https://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf // @@ -190,7 +190,8 @@ cfg_if::cfg_if! { ) -> uw::_Unwind_Reason_Code; } } - } else { + } + _ => { // Default personality routine, which is used directly on most targets // and indirectly on Windows x86_64 via SEH. unsafe extern "C" fn rust_eh_personality_impl( @@ -233,8 +234,8 @@ cfg_if::cfg_if! { } } - cfg_if::cfg_if! { - if #[cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu"))] { + cfg_match! { + cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu")) => { // On x86_64 MinGW targets, the unwinding mechanism is SEH however the unwind // handler data (aka LSDA) uses GCC-compatible encoding. #[lang = "eh_personality"] @@ -253,7 +254,8 @@ cfg_if::cfg_if! { rust_eh_personality_impl, ) } - } else { + } + _ => { // The personality routine for most of our targets. #[lang = "eh_personality"] unsafe extern "C" fn rust_eh_personality( diff --git a/library/std/src/sys/personality/mod.rs b/library/std/src/sys/personality/mod.rs index 386a399f53228..cf58569678743 100644 --- a/library/std/src/sys/personality/mod.rs +++ b/library/std/src/sys/personality/mod.rs @@ -13,10 +13,11 @@ mod dwarf; #[cfg(not(test))] -cfg_if::cfg_if! { - if #[cfg(target_os = "emscripten")] { +cfg_match! { + cfg(target_os = "emscripten") => { mod emcc; - } else if #[cfg(target_env = "msvc")] { + } + cfg(target_env = "msvc") => { // This is required by the compiler to exist (e.g., it's a lang item), // but it's never actually called by the compiler because // _CxxFrameHandler3 is the personality function that is always used. @@ -25,15 +26,17 @@ cfg_if::cfg_if! { fn rust_eh_personality() { core::intrinsics::abort() } - } else if #[cfg(any( + } + cfg(any( all(target_family = "windows", target_env = "gnu"), target_os = "psp", target_os = "solid_asp3", all(target_family = "unix", not(target_os = "espidf"), not(target_os = "l4re")), all(target_vendor = "fortanix", target_env = "sgx"), - ))] { + )) => { mod gcc; - } else { + } + _ => { // Targets that don't support unwinding. // - family=wasm // - os=none ("bare metal" targets) diff --git a/library/std/src/sys/unix/alloc.rs b/library/std/src/sys/unix/alloc.rs index af0089978ecbb..c289115891446 100644 --- a/library/std/src/sys/unix/alloc.rs +++ b/library/std/src/sys/unix/alloc.rs @@ -52,8 +52,8 @@ unsafe impl GlobalAlloc for System { } } -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "android", target_os = "illumos", target_os = "redox", @@ -61,7 +61,7 @@ cfg_if::cfg_if! { target_os = "espidf", target_os = "horizon", target_os = "vita", - ))] { + )) => { #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { // On android we currently target API level 9 which unfortunately @@ -83,7 +83,8 @@ cfg_if::cfg_if! { // /memory/aligned_memory.cc libc::memalign(layout.align(), layout.size()) as *mut u8 } - } else if #[cfg(target_os = "wasi")] { + } + cfg(target_os = "wasi") => { #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { // C11 aligned_alloc requires that the size be a multiple of the alignment. @@ -92,7 +93,8 @@ cfg_if::cfg_if! { let size = layout.size().next_multiple_of(align); libc::aligned_alloc(align, size) as *mut u8 } - } else { + } + _ => { #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let mut out = ptr::null_mut(); diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs index b2e0e49ad736d..93e1173b4f475 100644 --- a/library/std/src/sys/unix/locks/mod.rs +++ b/library/std/src/sys/unix/locks/mod.rs @@ -1,26 +1,28 @@ -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "linux", target_os = "android", all(target_os = "emscripten", target_feature = "atomics"), target_os = "freebsd", target_os = "openbsd", target_os = "dragonfly", - ))] { + )) => { mod futex_mutex; mod futex_rwlock; mod futex_condvar; pub(crate) use futex_mutex::Mutex; pub(crate) use futex_rwlock::RwLock; pub(crate) use futex_condvar::Condvar; - } else if #[cfg(target_os = "fuchsia")] { + } + cfg(target_os = "fuchsia") => { mod fuchsia_mutex; mod futex_rwlock; mod futex_condvar; pub(crate) use fuchsia_mutex::Mutex; pub(crate) use futex_rwlock::RwLock; pub(crate) use futex_condvar::Condvar; - } else { + } + _ => { mod pthread_mutex; mod pthread_rwlock; mod pthread_condvar; diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 3edafde71e937..e46c8e74a06fb 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -374,31 +374,36 @@ pub fn abort_internal() -> ! { unsafe { libc::abort() } } -cfg_if::cfg_if! { - if #[cfg(target_os = "android")] { +cfg_match! { + cfg(target_os = "android") => { #[link(name = "dl", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "dl", cfg(not(target_feature = "crt-static")))] #[link(name = "log", cfg(not(target_feature = "crt-static")))] extern "C" {} - } else if #[cfg(target_os = "freebsd")] { + } + cfg(target_os = "freebsd") => { #[link(name = "execinfo")] #[link(name = "pthread")] extern "C" {} - } else if #[cfg(target_os = "netbsd")] { + } + cfg(target_os = "netbsd") => { #[link(name = "pthread")] #[link(name = "rt")] extern "C" {} - } else if #[cfg(any(target_os = "dragonfly", target_os = "openbsd"))] { + } + cfg(any(target_os = "dragonfly", target_os = "openbsd")) => { #[link(name = "pthread")] extern "C" {} - } else if #[cfg(target_os = "solaris")] { + } + cfg(target_os = "solaris") => { #[link(name = "socket")] #[link(name = "posix4")] #[link(name = "pthread")] #[link(name = "resolv")] extern "C" {} - } else if #[cfg(target_os = "illumos")] { + } + cfg(target_os = "illumos") => { #[link(name = "socket")] #[link(name = "posix4")] #[link(name = "pthread")] @@ -407,23 +412,28 @@ cfg_if::cfg_if! { // Use libumem for the (malloc-compatible) allocator #[link(name = "umem")] extern "C" {} - } else if #[cfg(target_os = "macos")] { + } + cfg(target_os = "macos") => { #[link(name = "System")] extern "C" {} - } else if #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos"))] { + } + cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos")) => { #[link(name = "System")] #[link(name = "objc")] #[link(name = "Security", kind = "framework")] #[link(name = "Foundation", kind = "framework")] extern "C" {} - } else if #[cfg(target_os = "fuchsia")] { + } + cfg(target_os = "fuchsia") => { #[link(name = "zircon")] #[link(name = "fdio")] extern "C" {} - } else if #[cfg(all(target_os = "linux", target_env = "uclibc"))] { + } + cfg(all(target_os = "linux", target_env = "uclibc")) => { #[link(name = "dl")] extern "C" {} - } else if #[cfg(target_os = "vita")] { + } + cfg(target_os = "vita") => { #[link(name = "pthread", kind = "static", modifiers = "-bundle")] extern "C" {} } diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 01ff375d21517..946cacf52b5b3 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -31,10 +31,11 @@ use libc::{c_char, c_int, c_void}; const TMPBUF_SZ: usize = 128; -cfg_if::cfg_if! { - if #[cfg(target_os = "redox")] { +cfg_match! { + cfg(target_os = "redox") => { const PATH_SEPARATOR: u8 = b';'; - } else { + } + _ => { const PATH_SEPARATOR: u8 = b':'; } } diff --git a/library/std/src/sys/unix/process/mod.rs b/library/std/src/sys/unix/process/mod.rs index 0cf163d9fb8e9..e84dec691dc51 100644 --- a/library/std/src/sys/unix/process/mod.rs +++ b/library/std/src/sys/unix/process/mod.rs @@ -6,18 +6,21 @@ pub use crate::sys_common::process::CommandEnvs; #[cfg_attr(any(target_os = "espidf", target_os = "horizon"), allow(unused))] mod process_common; -cfg_if::cfg_if! { - if #[cfg(target_os = "fuchsia")] { +cfg_match! { + cfg(target_os = "fuchsia") => { #[path = "process_fuchsia.rs"] mod process_inner; mod zircon; - } else if #[cfg(target_os = "vxworks")] { + } + cfg(target_os = "vxworks") => { #[path = "process_vxworks.rs"] mod process_inner; - } else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))] { + } + cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita")) => { #[path = "process_unsupported.rs"] mod process_inner; - } else { + } + _ => { #[path = "process_unix.rs"] mod process_inner; } diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 1ca11a7f9d763..f5e892a620b61 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -20,14 +20,17 @@ use crate::sys::fs::OpenOptions; use libc::{c_char, c_int, gid_t, pid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS}; -cfg_if::cfg_if! { - if #[cfg(target_os = "fuchsia")] { +cfg_match! { + cfg(target_os = "fuchsia") => { // fuchsia doesn't have /dev/null - } else if #[cfg(target_os = "redox")] { + } + cfg(target_os = "redox") => { const DEV_NULL: &str = "null:\0"; - } else if #[cfg(target_os = "vxworks")] { + } + cfg(target_os = "vxworks") => { const DEV_NULL: &str = "/null\0"; - } else { + } + _ => { const DEV_NULL: &str = "/dev/null\0"; } } @@ -37,8 +40,8 @@ cfg_if::cfg_if! { // to support older Android version (independent of libc version). // The following implementations are based on // https://github.com/aosp-mirror/platform_bionic/blob/ad8dcd6023294b646e5a8288c0ed431b0845da49/libc/include/android/legacy_signal_inlines.h -cfg_if::cfg_if! { - if #[cfg(target_os = "android")] { +cfg_match! { + cfg(target_os = "android") => { #[allow(dead_code)] pub unsafe fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int { set.write_bytes(0u8, 1); @@ -74,7 +77,8 @@ cfg_if::cfg_if! { raw[bit / LONG_BIT] |= 1 << (bit % LONG_BIT); return 0; } - } else { + } + _ => { pub use libc::{sigemptyset, sigaddset}; } } diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 564f8c482902b..ffa9a5eb6ac8d 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -35,9 +35,8 @@ use libc::{c_int, pid_t}; )))] use libc::{gid_t, uid_t}; -cfg_if::cfg_if! { - if #[cfg(all(target_os = "nto", target_env = "nto71"))] { - use crate::thread; +cfg_match! { + cfg(all(target_os = "nto", target_env = "nto71")) => { use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t}; use crate::time::Duration; use crate::sync::LazyLock; diff --git a/library/std/src/sys/unix/thread_parking/mod.rs b/library/std/src/sys/unix/thread_parking/mod.rs index 185333c072f49..b3c9b69d1a87f 100644 --- a/library/std/src/sys/unix/thread_parking/mod.rs +++ b/library/std/src/sys/unix/thread_parking/mod.rs @@ -10,8 +10,8 @@ target_os = "fuchsia", )))] -cfg_if::cfg_if! { - if #[cfg(all( +cfg_match! { + cfg(all( any( target_os = "macos", target_os = "ios", @@ -19,13 +19,15 @@ cfg_if::cfg_if! { target_os = "tvos", ), not(miri), - ))] { + )) => { mod darwin; pub use darwin::Parker; - } else if #[cfg(target_os = "netbsd")] { + } + cfg(target_os = "netbsd") => { mod netbsd; pub use netbsd::{current, park, park_timeout, unpark, ThreadId}; - } else { + } + _ => { mod pthread; pub use pthread::Parker; } diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index 5cbb5cb65ba8d..74e649f6f57f0 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -48,8 +48,8 @@ pub mod thread_local_dtor; pub mod thread_local_key; pub mod time; -cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { +cfg_match! { + cfg(target_feature = "atomics") => { #[path = "../unix/locks"] pub mod locks { #![allow(unsafe_op_in_unsafe_fn)] @@ -60,7 +60,8 @@ cfg_if::cfg_if! { pub(crate) use futex_mutex::Mutex; pub(crate) use futex_rwlock::RwLock; } - } else { + } + _ => { #[path = "../unsupported/locks/mod.rs"] pub mod locks; #[path = "../unsupported/once.rs"] diff --git a/library/std/src/sys/wasi/os.rs b/library/std/src/sys/wasi/os.rs index d53bddd8e9dfe..19fecef29ca36 100644 --- a/library/std/src/sys/wasi/os.rs +++ b/library/std/src/sys/wasi/os.rs @@ -25,8 +25,8 @@ mod libc { } } -cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { +cfg_match! { + cfg(target_feature = "atomics") => { // Access to the environment must be protected by a lock in multi-threaded scenarios. use crate::sync::{PoisonError, RwLock}; static ENV_LOCK: RwLock<()> = RwLock::new(()); @@ -36,7 +36,8 @@ cfg_if::cfg_if! { pub fn env_write_lock() -> impl Drop { ENV_LOCK.write().unwrap_or_else(PoisonError::into_inner) } - } else { + } + _ => { // No need for a lock if we are single-threaded. pub fn env_read_lock() -> impl Drop { Box::new(()) diff --git a/library/std/src/sys/wasi/thread.rs b/library/std/src/sys/wasi/thread.rs index a0eefa8811a39..48c8b24618f5f 100644 --- a/library/std/src/sys/wasi/thread.rs +++ b/library/std/src/sys/wasi/thread.rs @@ -5,8 +5,8 @@ use crate::num::NonZeroUsize; use crate::sys::unsupported; use crate::time::Duration; -cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { +cfg_match! { + cfg(target_feature = "atomics") => { use crate::cmp; use crate::ptr; use crate::sys::os; @@ -61,7 +61,8 @@ cfg_if::cfg_if! { debug_assert_eq!(ret, 0); } } - } else { + } + _ => { pub struct Thread(!); } } @@ -70,8 +71,8 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements - cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { + cfg_match! { + cfg(target_feature = "atomics") => { pub unsafe fn new(stack: usize, p: Box) -> io::Result { let p = Box::into_raw(Box::new(p)); let mut native: libc::pthread_t = mem::zeroed(); @@ -118,7 +119,8 @@ impl Thread { ptr::null_mut() } } - } else { + } + _ => { pub unsafe fn new(_stack: usize, _p: Box) -> io::Result { unsupported() } @@ -170,8 +172,8 @@ impl Thread { } pub fn join(self) { - cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { + cfg_match! { + cfg(target_feature = "atomics") => { unsafe { let ret = libc::pthread_join(self.id, ptr::null_mut()); mem::forget(self); @@ -179,7 +181,8 @@ impl Thread { rtabort!("failed to join thread: {}", io::Error::from_raw_os_error(ret)); } } - } else { + } + _ => { self.0 } } diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs index 6c05b56e1bfc0..6b1661e9c119a 100644 --- a/library/std/src/sys/wasm/mod.rs +++ b/library/std/src/sys/wasm/mod.rs @@ -47,8 +47,8 @@ pub mod thread_local_key; #[path = "../unsupported/time.rs"] pub mod time; -cfg_if::cfg_if! { - if #[cfg(target_feature = "atomics")] { +cfg_match! { + cfg(target_feature = "atomics") => { #[path = "../unix/locks"] pub mod locks { #![allow(unsafe_op_in_unsafe_fn)] @@ -63,7 +63,8 @@ cfg_if::cfg_if! { pub mod futex; #[path = "atomics/thread.rs"] pub mod thread; - } else { + } + _ => { #[path = "../unsupported/locks/mod.rs"] pub mod locks; #[path = "../unsupported/once.rs"] diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index f3637cbb981dc..5b306bfb1bea9 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -189,11 +189,8 @@ pub struct in6_addr { } // 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; pub unsafe extern "system" fn WriteFileEx( hFile: BorrowedHandle<'_>, @@ -263,8 +260,8 @@ pub unsafe fn getaddrinfo( windows_sys::getaddrinfo(node.cast::(), service.cast::(), hints, res) } -cfg_if::cfg_if! { -if #[cfg(not(target_vendor = "uwp"))] { +cfg_match! { +cfg(not(target_vendor = "uwp")) => { pub unsafe fn NtReadFile( filehandle: BorrowedHandle<'_>, event: HANDLE, @@ -435,26 +432,27 @@ compat_fn_with_fallback! { // are not included in the win32 metadata. We work around that by defining them here. // // Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys -cfg_if::cfg_if! { -if #[cfg(not(target_vendor = "uwp"))] { - #[link(name = "kernel32")] - extern "system" { - pub fn AddVectoredExceptionHandler( - first: u32, - handler: PVECTORED_EXCEPTION_HANDLER, - ) -> *mut c_void; - } - pub type PVECTORED_EXCEPTION_HANDLER = Option< - unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32, - >; - #[repr(C)] - pub struct EXCEPTION_POINTERS { - pub ExceptionRecord: *mut EXCEPTION_RECORD, - pub ContextRecord: *mut CONTEXT, +cfg_match! { + cfg(not(target_vendor = "uwp")) => { + #[link(name = "kernel32")] + extern "system" { + pub fn AddVectoredExceptionHandler( + first: u32, + handler: PVECTORED_EXCEPTION_HANDLER, + ) -> *mut c_void; + } + pub type PVECTORED_EXCEPTION_HANDLER = Option< + unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32, + >; + #[repr(C)] + pub struct EXCEPTION_POINTERS { + pub ExceptionRecord: *mut EXCEPTION_RECORD, + pub ContextRecord: *mut CONTEXT, + } + #[cfg(target_arch = "arm")] + pub enum CONTEXT {} } - #[cfg(target_arch = "arm")] - pub enum CONTEXT {} -}} +} #[link(name = "ws2_32")] extern "system" { diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index b609ad2472c62..f513493fa9a32 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -35,10 +35,11 @@ pub mod thread_local_dtor; pub mod thread_local_key; pub mod thread_parking; pub mod time; -cfg_if::cfg_if! { - if #[cfg(not(target_vendor = "uwp"))] { +cfg_match! { + cfg(not(target_vendor = "uwp")) => { pub mod stack_overflow; - } else { + } + _ => { pub mod stack_overflow_uwp; pub use self::stack_overflow_uwp as stack_overflow; } diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index e18638f2a5f54..1c282b3abecb7 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -34,23 +34,25 @@ pub mod thread_parking; pub mod wstr; pub mod wtf8; -cfg_if::cfg_if! { - if #[cfg(target_os = "windows")] { +cfg_match! { + cfg(target_os = "windows") => { pub use crate::sys::thread_local_key; - } else { + } + _ => { pub mod thread_local_key; } } -cfg_if::cfg_if! { - if #[cfg(any(target_os = "l4re", +cfg_match! { + cfg(any(target_os = "l4re", target_os = "uefi", feature = "restricted-std", all(target_family = "wasm", not(target_os = "emscripten")), target_os = "xous", - all(target_vendor = "fortanix", target_env = "sgx")))] { + all(target_vendor = "fortanix", target_env = "sgx"))) => { pub use crate::sys::net; - } else { + } + _ => { pub mod net; } } diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 4f5b17deaa2da..f74a99a4001d1 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -15,42 +15,46 @@ use crate::time::Duration; use crate::ffi::{c_int, c_void}; -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "tvos", target_os = "macos", target_os = "watchos", target_os = "openbsd", target_os = "netbsd", target_os = "illumos", - target_os = "solaris", target_os = "haiku", target_os = "l4re", target_os = "nto"))] { + target_os = "solaris", target_os = "haiku", target_os = "l4re", target_os = "nto")) => { use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; - } else { + } + _ => { use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP; } } -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "linux", target_os = "android", target_os = "hurd", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", - target_os = "haiku", target_os = "nto"))] { + target_os = "haiku", target_os = "nto") + ) => { use libc::MSG_NOSIGNAL; - } else { + } + _ => { const MSG_NOSIGNAL: c_int = 0x0; } } -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "solaris", target_os = "illumos", - target_os = "nto"))] { + target_os = "nto")) => { use crate::ffi::c_uchar; type IpV4MultiCastType = c_uchar; - } else { + } + _ => { type IpV4MultiCastType = c_int; } } diff --git a/library/std/src/sys_common/once/mod.rs b/library/std/src/sys_common/once/mod.rs index 359697d831317..43fd502d80e74 100644 --- a/library/std/src/sys_common/once/mod.rs +++ b/library/std/src/sys_common/once/mod.rs @@ -7,8 +7,8 @@ // This also gives us the opportunity to optimize the implementation a bit which // should help the fast path on call sites. -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "linux", target_os = "android", all(target_arch = "wasm32", target_feature = "atomics"), @@ -17,18 +17,20 @@ cfg_if::cfg_if! { target_os = "dragonfly", target_os = "fuchsia", target_os = "hermit", - ))] { + )) => { mod futex; pub use futex::{Once, OnceState}; - } else if #[cfg(any( + } + cfg(any( windows, target_family = "unix", all(target_vendor = "fortanix", target_env = "sgx"), target_os = "solid_asp3", - ))] { + )) => { mod queue; pub use queue::{Once, OnceState}; - } else { + } + _ => { pub use crate::sys::once::{Once, OnceState}; } } diff --git a/library/std/src/sys_common/thread_parking/mod.rs b/library/std/src/sys_common/thread_parking/mod.rs index c4d3f9ea2f427..ea3c4cfbab2cc 100644 --- a/library/std/src/sys_common/thread_parking/mod.rs +++ b/library/std/src/sys_common/thread_parking/mod.rs @@ -1,5 +1,5 @@ -cfg_if::cfg_if! { - if #[cfg(any( +cfg_match! { + cfg(any( target_os = "linux", target_os = "android", all(target_arch = "wasm32", target_feature = "atomics"), @@ -8,17 +8,19 @@ cfg_if::cfg_if! { target_os = "dragonfly", target_os = "fuchsia", target_os = "hermit", - ))] { + )) => { mod futex; pub use futex::Parker; - } else if #[cfg(any( + } + cfg(any( target_os = "netbsd", all(target_vendor = "fortanix", target_env = "sgx"), target_os = "solid_asp3", - ))] { + )) => { mod id; pub use id::Parker; - } else { + } + _ => { pub use crate::sys::thread_parking::Parker; } } diff --git a/library/unwind/Cargo.toml b/library/unwind/Cargo.toml index eab2717c45233..101ba3537529a 100644 --- a/library/unwind/Cargo.toml +++ b/library/unwind/Cargo.toml @@ -17,7 +17,6 @@ doc = false core = { path = "../core" } libc = { version = "0.2.79", features = ['rustc-dep-of-std'], default-features = false } compiler_builtins = "0.1.0" -cfg-if = "1.0" [build-dependencies] cc = "1.0.76" diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index df4f286a526bd..44b11759a4517 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] +#![feature(cfg_match)] #![feature(link_cfg)] #![feature(staged_api)] #![feature(c_unwind)] @@ -7,25 +8,28 @@ #![cfg_attr(not(target_env = "msvc"), feature(libc))] #![allow(internal_features)] -cfg_if::cfg_if! { - if #[cfg(target_env = "msvc")] { +cfg_match! { + cfg(target_env = "msvc") => { // Windows MSVC no extra unwinder support needed - } else if #[cfg(any( + } + cfg(any( target_os = "l4re", target_os = "none", target_os = "espidf", - ))] { + )) => { // These "unix" family members do not have unwinder. - } else if #[cfg(any( + } + cfg(any( unix, windows, target_os = "psp", target_os = "solid_asp3", all(target_vendor = "fortanix", target_env = "sgx"), - ))] { + )) => { mod libunwind; pub use libunwind::*; - } else { + } + _ => { // no unwinder on the system! // - wasm32 (not emscripten, which is "unix" family) // - os=none ("bare metal" targets) @@ -38,17 +42,20 @@ cfg_if::cfg_if! { } #[cfg(target_env = "musl")] -cfg_if::cfg_if! { - if #[cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind"))] { +cfg_match! { + cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind")) => { compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time"); - } else if #[cfg(feature = "llvm-libunwind")] { + } + cfg(feature = "llvm-libunwind") => { #[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} - } else if #[cfg(feature = "system-llvm-libunwind")] { + } + cfg(feature = "system-llvm-libunwind") => { #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "unwind", cfg(not(target_feature = "crt-static")))] extern "C" {} - } else { + } + _ => { #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] extern "C" {} @@ -58,13 +65,15 @@ cfg_if::cfg_if! { // This is the same as musl except that we default to using the system libunwind // instead of libgcc. #[cfg(target_env = "ohos")] -cfg_if::cfg_if! { - if #[cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind"))] { +cfg_match! { + cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind")) => { compile_error!("`llvm-libunwind` and `system-llvm-libunwind` cannot be enabled at the same time"); - } else if #[cfg(feature = "llvm-libunwind")] { + } + cfg(feature = "llvm-libunwind") => { #[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} - } else { + } + _ => { #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "unwind", cfg(not(target_feature = "crt-static")))] extern "C" {} @@ -72,14 +81,16 @@ cfg_if::cfg_if! { } #[cfg(target_os = "android")] -cfg_if::cfg_if! { - if #[cfg(feature = "llvm-libunwind")] { +cfg_match! { + cfg(feature = "llvm-libunwind") => { compile_error!("`llvm-libunwind` is not supported for Android targets"); - } else if #[cfg(feature = "system-llvm-libunwind")] { + } + cfg(feature = "system-llvm-libunwind") => { #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "unwind", cfg(not(target_feature = "crt-static")))] extern "C" {} - } else { + } + _ => { #[link(name = "gcc", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc", cfg(not(target_feature = "crt-static")))] extern "C" {} diff --git a/library/unwind/src/libunwind.rs b/library/unwind/src/libunwind.rs index a2bfa8e96dd22..22af1f9cf911e 100644 --- a/library/unwind/src/libunwind.rs +++ b/library/unwind/src/libunwind.rs @@ -119,8 +119,8 @@ extern "C" { pub fn _Unwind_GetDataRelBase(ctx: *mut _Unwind_Context) -> _Unwind_Ptr; } -cfg_if::cfg_if! { -if #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "netbsd", not(target_arch = "arm")))] { +cfg_match! { +cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "netbsd", not(target_arch = "arm"))) => { // Not ARM EHABI #[repr(C)] #[derive(Copy, Clone, PartialEq)] @@ -146,8 +146,8 @@ if #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos", targe -> _Unwind_Word; pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void; } - -} else { +} +_ => { // ARM EHABI #[repr(C)] #[derive(Copy, Clone, PartialEq)] @@ -254,8 +254,8 @@ if #[cfg(any(target_os = "ios", target_os = "tvos", target_os = "watchos", targe } } // cfg_if! -cfg_if::cfg_if! { -if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { +cfg_match! { +cfg(not(all(target_os = "ios", target_arch = "arm"))) => { // Not 32-bit iOS #[cfg_attr( all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), @@ -273,7 +273,8 @@ if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { trace_argument: *mut c_void) -> _Unwind_Reason_Code; } -} else { +} +_ => { // 32-bit iOS uses SjLj and does not provide _Unwind_Backtrace() extern "C-unwind" { pub fn _Unwind_SjLj_RaiseException(e: *mut _Unwind_Exception) -> _Unwind_Reason_Code; @@ -283,8 +284,8 @@ if #[cfg(not(all(target_os = "ios", target_arch = "arm")))] { } } // cfg_if! -cfg_if::cfg_if! { -if #[cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu"))] { +cfg_match! { +cfg(all(windows, any(target_arch = "aarch64", target_arch = "x86_64"), target_env = "gnu")) => { // We declare these as opaque types. This is fine since you just need to // pass them to _GCC_specific_handler and forget about them. pub enum EXCEPTION_RECORD {}