Skip to content

Commit 1541672

Browse files
committed
Initiate the inner usage of cfg_match
1 parent 781ebbe commit 1541672

File tree

36 files changed

+324
-314
lines changed

36 files changed

+324
-314
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -5836,7 +5836,6 @@ name = "unwind"
58365836
version = "0.0.0"
58375837
dependencies = [
58385838
"cc",
5839-
"cfg-if",
58405839
"compiler_builtins",
58415840
"core",
58425841
"libc",

library/core/src/ffi/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ pub type c_ptrdiff_t = isize;
9797
pub type c_ssize_t = isize;
9898

9999
mod c_char_definition {
100-
cfg_if! {
100+
cfg_match! {
101101
// These are the targets on which c_char is unsigned.
102-
if #[cfg(any(
102+
cfg(any(
103103
all(
104104
target_os = "linux",
105105
any(
@@ -150,10 +150,11 @@ mod c_char_definition {
150150
),
151151
all(target_os = "nto", target_arch = "aarch64"),
152152
target_os = "horizon"
153-
))] {
153+
)) => {
154154
pub type c_char = u8;
155155
pub type NonZero_c_char = crate::num::NonZeroU8;
156-
} else {
156+
}
157+
_ => {
157158
// On every other target, c_char is signed.
158159
pub type c_char = i8;
159160
pub type NonZero_c_char = crate::num::NonZeroI8;
@@ -162,13 +163,14 @@ mod c_char_definition {
162163
}
163164

164165
mod c_int_definition {
165-
cfg_if! {
166-
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
166+
cfg_match! {
167+
cfg(any(target_arch = "avr", target_arch = "msp430")) => {
167168
pub type c_int = i16;
168169
pub type NonZero_c_int = crate::num::NonZeroI16;
169170
pub type c_uint = u16;
170171
pub type NonZero_c_uint = crate::num::NonZeroU16;
171-
} else {
172+
}
173+
_ => {
172174
pub type c_int = i32;
173175
pub type NonZero_c_int = crate::num::NonZeroI32;
174176
pub type c_uint = u32;
@@ -178,13 +180,14 @@ mod c_int_definition {
178180
}
179181

180182
mod c_long_definition {
181-
cfg_if! {
182-
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
183+
cfg_match! {
184+
cfg(all(target_pointer_width = "64", not(windows))) => {
183185
pub type c_long = i64;
184186
pub type NonZero_c_long = crate::num::NonZeroI64;
185187
pub type c_ulong = u64;
186188
pub type NonZero_c_ulong = crate::num::NonZeroU64;
187-
} else {
189+
}
190+
_ =>{
188191
// The minimal size of `long` in the C standard is 32 bits
189192
pub type c_long = i32;
190193
pub type NonZero_c_long = crate::num::NonZeroI32;

library/core/src/internal_macros.rs

-77
Original file line numberDiff line numberDiff line change
@@ -116,80 +116,3 @@ macro_rules! impl_fn_for_zst {
116116
)+
117117
}
118118
}
119-
120-
/// A macro for defining `#[cfg]` if-else statements.
121-
///
122-
/// `cfg_if` is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade
123-
/// of `#[cfg]` cases, emitting the implementation which matches first.
124-
///
125-
/// This allows you to conveniently provide a long list `#[cfg]`'d blocks of code without having to
126-
/// rewrite each clause multiple times.
127-
///
128-
/// # Example
129-
///
130-
/// ```ignore(cannot-test-this-because-non-exported-macro)
131-
/// cfg_if! {
132-
/// if #[cfg(unix)] {
133-
/// fn foo() { /* unix specific functionality */ }
134-
/// } else if #[cfg(target_pointer_width = "32")] {
135-
/// fn foo() { /* non-unix, 32-bit functionality */ }
136-
/// } else {
137-
/// fn foo() { /* fallback implementation */ }
138-
/// }
139-
/// }
140-
///
141-
/// # fn main() {}
142-
/// ```
143-
// This is a copy of `cfg_if!` from the `cfg_if` crate.
144-
// The recursive invocations should use $crate if this is ever exported.
145-
macro_rules! cfg_if {
146-
// match if/else chains with a final `else`
147-
(
148-
$(
149-
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
150-
) else+
151-
else { $( $e_tokens:tt )* }
152-
) => {
153-
cfg_if! {
154-
@__items () ;
155-
$(
156-
(( $i_meta ) ( $( $i_tokens )* )) ,
157-
)+
158-
(() ( $( $e_tokens )* )) ,
159-
}
160-
};
161-
162-
// Internal and recursive macro to emit all the items
163-
//
164-
// Collects all the previous cfgs in a list at the beginning, so they can be
165-
// negated. After the semicolon is all the remaining items.
166-
(@__items ( $( $_:meta , )* ) ; ) => {};
167-
(
168-
@__items ( $( $no:meta , )* ) ;
169-
(( $( $yes:meta )? ) ( $( $tokens:tt )* )) ,
170-
$( $rest:tt , )*
171-
) => {
172-
// Emit all items within one block, applying an appropriate #[cfg]. The
173-
// #[cfg] will require all `$yes` matchers specified and must also negate
174-
// all previous matchers.
175-
#[cfg(all(
176-
$( $yes , )?
177-
not(any( $( $no ),* ))
178-
))]
179-
cfg_if! { @__identity $( $tokens )* }
180-
181-
// Recurse to emit all other items in `$rest`, and when we do so add all
182-
// our `$yes` matchers to the list of `$no` matchers as future emissions
183-
// will have to negate everything we just matched as well.
184-
cfg_if! {
185-
@__items ( $( $no , )* $( $yes , )? ) ;
186-
$( $rest , )*
187-
}
188-
};
189-
190-
// Internal macro to make __apply work out right for different match types,
191-
// because of how macros match/expand stuff.
192-
(@__identity $( $tokens:tt )* ) => {
193-
$( $tokens )*
194-
};
195-
}

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
// tidy-alphabetical-start
113113
#![cfg_attr(bootstrap, feature(no_coverage))] // rust-lang/rust#84605
114114
#![cfg_attr(not(bootstrap), feature(coverage_attribute))] // rust-lang/rust#84605
115+
#![feature(cfg_match)]
115116
#![feature(char_indices_offset)]
116117
#![feature(const_align_of_val)]
117118
#![feature(const_align_of_val_raw)]

library/panic_abort/src/lib.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
99
#![panic_runtime]
1010
#![allow(unused_features)]
11+
#![feature(cfg_match)]
1112
#![feature(core_intrinsics)]
1213
#![feature(panic_runtime)]
1314
#![feature(std_internals)]
@@ -37,24 +38,26 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
3738

3839
abort();
3940

40-
cfg_if::cfg_if! {
41-
if #[cfg(any(unix, target_os = "solid_asp3"))] {
41+
cfg_match! {
42+
cfg(any(unix, target_os = "solid_asp3")) => {
4243
unsafe fn abort() -> ! {
4344
libc::abort();
4445
}
45-
} else if #[cfg(any(target_os = "hermit",
46-
all(target_vendor = "fortanix", target_env = "sgx"),
47-
target_os = "xous",
48-
target_os = "uefi",
49-
))] {
46+
}
47+
cfg(any(target_os = "hermit",
48+
all(target_vendor = "fortanix", target_env = "sgx"),
49+
target_os = "xous",
50+
target_os = "uefi",
51+
)) => {
5052
unsafe fn abort() -> ! {
5153
// call std::sys::abort_internal
5254
extern "C" {
5355
pub fn __rust_abort() -> !;
5456
}
5557
__rust_abort();
5658
}
57-
} else if #[cfg(all(windows, not(miri)))] {
59+
}
60+
cfg(all(windows, not(miri))) => {
5861
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
5962
// and later, this will terminate the process immediately without running any
6063
// 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 {
8184
}
8285
core::intrinsics::unreachable();
8386
}
84-
} else {
87+
}
88+
_ => {
8589
unsafe fn abort() -> ! {
8690
core::intrinsics::abort();
8791
}

library/panic_unwind/src/lib.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![no_std]
1515
#![unstable(feature = "panic_unwind", issue = "32837")]
1616
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
17+
#![feature(cfg_match)]
1718
#![feature(core_intrinsics)]
1819
#![feature(lang_items)]
1920
#![feature(panic_unwind)]
@@ -31,31 +32,36 @@ use alloc::boxed::Box;
3132
use core::any::Any;
3233
use core::panic::PanicPayload;
3334

34-
cfg_if::cfg_if! {
35-
if #[cfg(target_os = "emscripten")] {
35+
cfg_match! {
36+
cfg(target_os = "emscripten") => {
3637
#[path = "emcc.rs"]
3738
mod real_imp;
38-
} else if #[cfg(target_os = "hermit")] {
39+
}
40+
cfg(target_os = "hermit") => {
3941
#[path = "hermit.rs"]
4042
mod real_imp;
41-
} else if #[cfg(target_os = "l4re")] {
43+
}
44+
cfg(target_os = "l4re") => {
4245
// L4Re is unix family but does not yet support unwinding.
4346
#[path = "dummy.rs"]
4447
mod real_imp;
45-
} else if #[cfg(all(target_env = "msvc", not(target_arch = "arm")))] {
48+
}
49+
cfg(all(target_env = "msvc", not(target_arch = "arm"))) => {
4650
// LLVM does not support unwinding on 32 bit ARM msvc (thumbv7a-pc-windows-msvc)
4751
#[path = "seh.rs"]
4852
mod real_imp;
49-
} else if #[cfg(any(
53+
}
54+
cfg(any(
5055
all(target_family = "windows", target_env = "gnu"),
5156
target_os = "psp",
5257
target_os = "solid_asp3",
5358
all(target_family = "unix", not(target_os = "espidf")),
5459
all(target_vendor = "fortanix", target_env = "sgx"),
55-
))] {
60+
)) => {
5661
#[path = "gcc.rs"]
5762
mod real_imp;
58-
} else {
63+
}
64+
_ => {
5965
// Targets that don't support unwinding.
6066
// - family=wasm
6167
// - os=none ("bare metal" targets)
@@ -68,14 +74,15 @@ cfg_if::cfg_if! {
6874
}
6975
}
7076

71-
cfg_if::cfg_if! {
72-
if #[cfg(miri)] {
77+
cfg_match! {
78+
cfg(miri) => {
7379
// Use the Miri runtime.
7480
// We still need to also load the normal runtime above, as rustc expects certain lang
7581
// items from there to be defined.
7682
#[path = "miri.rs"]
7783
mod imp;
78-
} else {
84+
}
85+
_ => {
7986
// Use the real runtime.
8087
use real_imp as imp;
8188
}

library/panic_unwind/src/seh.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,11 @@ macro_rules! define_cleanup {
253253
}
254254
}
255255
}
256-
cfg_if::cfg_if! {
257-
if #[cfg(target_arch = "x86")] {
256+
cfg_match! {
257+
cfg(target_arch = "x86") => {
258258
define_cleanup!("thiscall" "thiscall-unwind");
259-
} else {
259+
}
260+
_ => {
260261
define_cleanup!("C" "C-unwind");
261262
}
262263
}

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
//
306306
// Library features (core):
307307
// tidy-alphabetical-start
308+
#![feature(cfg_match)]
308309
#![feature(char_internals)]
309310
#![feature(core_intrinsics)]
310311
#![feature(duration_constants)]

library/std/src/os/unix/process.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ use crate::sealed::Sealed;
1212
use crate::sys;
1313
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
1414

15-
use cfg_if::cfg_if;
16-
17-
cfg_if! {
18-
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
15+
cfg_match! {
16+
cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita")) => {
1917
type UserId = u16;
2018
type GroupId = u16;
21-
} else if #[cfg(target_os = "nto")] {
19+
}
20+
cfg(target_os = "nto") => {
2221
// Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP.
2322
// Only positive values should be used, see e.g.
2423
// https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html
2524
type UserId = i32;
2625
type GroupId = i32;
27-
} else {
26+
}
27+
_ => {
2828
type UserId = u32;
2929
type GroupId = u32;
3030
}

library/std/src/sys/common/thread_local/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
// "fast" key type is accessed via code generated via LLVM, where TLS keys are set up by the linker.
66
// "static" is for single-threaded platforms where a global static is sufficient.
77

8-
cfg_if::cfg_if! {
9-
if #[cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi"))] {
8+
cfg_match! {
9+
cfg(any(all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi")) => {
1010
#[doc(hidden)]
1111
mod static_local;
1212
#[doc(hidden)]
1313
pub use static_local::{Key, thread_local_inner};
14-
} else if #[cfg(target_thread_local)] {
14+
}
15+
cfg(target_thread_local) => {
1516
#[doc(hidden)]
1617
mod fast_local;
1718
#[doc(hidden)]
1819
pub use fast_local::{Key, thread_local_inner};
19-
} else {
20+
}
21+
_ => {
2022
#[doc(hidden)]
2123
mod os_local;
2224
#[doc(hidden)]

0 commit comments

Comments
 (0)