Skip to content

Commit 2a438a6

Browse files
authored
Rollup merge of rust-lang#116342 - c410-f3r:t3st3ss, r=Mark-Simulacrum
Initiate the inner usage of `cfg_match` (Library) cc rust-lang#115585 Continuation of rust-lang#116312
2 parents d3df8ff + 131cc37 commit 2a438a6

File tree

33 files changed

+280
-286
lines changed

33 files changed

+280
-286
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -5999,7 +5999,6 @@ dependencies = [
59995999
name = "unwind"
60006000
version = "0.0.0"
60016001
dependencies = [
6002-
"cfg-if",
60036002
"compiler_builtins",
60046003
"core",
60056004
"libc",

library/core/src/ffi/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ pub type c_ptrdiff_t = isize;
7171
pub type c_ssize_t = isize;
7272

7373
mod c_char_definition {
74-
cfg_if! {
74+
crate::cfg_match! {
7575
// These are the targets on which c_char is unsigned.
76-
if #[cfg(any(
76+
cfg(any(
7777
all(
7878
target_os = "linux",
7979
any(
@@ -124,33 +124,36 @@ mod c_char_definition {
124124
),
125125
all(target_os = "nto", target_arch = "aarch64"),
126126
target_os = "horizon"
127-
))] {
127+
)) => {
128128
pub type c_char = u8;
129-
} else {
129+
}
130+
_ => {
130131
// On every other target, c_char is signed.
131132
pub type c_char = i8;
132133
}
133134
}
134135
}
135136

136137
mod c_int_definition {
137-
cfg_if! {
138-
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
138+
crate::cfg_match! {
139+
cfg(any(target_arch = "avr", target_arch = "msp430")) => {
139140
pub type c_int = i16;
140141
pub type c_uint = u16;
141-
} else {
142+
}
143+
_ => {
142144
pub type c_int = i32;
143145
pub type c_uint = u32;
144146
}
145147
}
146148
}
147149

148150
mod c_long_definition {
149-
cfg_if! {
150-
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
151+
crate::cfg_match! {
152+
cfg(all(target_pointer_width = "64", not(windows))) => {
151153
pub type c_long = i64;
152154
pub type c_ulong = u64;
153-
} else {
155+
}
156+
_ =>{
154157
// The minimal size of `long` in the C standard is 32 bits
155158
pub type c_long = i32;
156159
pub type c_ulong = u32;

library/core/src/internal_macros.rs

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

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
//
112112
// Library features:
113113
// tidy-alphabetical-start
114+
#![feature(cfg_match)]
114115
#![feature(char_indices_offset)]
115116
#![feature(const_align_of_val)]
116117
#![feature(const_align_of_val_raw)]

library/panic_abort/src/lib.rs

+15-10
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)]
@@ -42,24 +43,26 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
4243

4344
abort();
4445

45-
cfg_if::cfg_if! {
46-
if #[cfg(any(unix, target_os = "solid_asp3"))] {
46+
cfg_match! {
47+
cfg(any(unix, target_os = "solid_asp3")) => {
4748
unsafe fn abort() -> ! {
4849
libc::abort();
4950
}
50-
} else if #[cfg(any(target_os = "hermit",
51-
all(target_vendor = "fortanix", target_env = "sgx"),
52-
target_os = "xous",
53-
target_os = "uefi",
54-
))] {
51+
}
52+
cfg(any(target_os = "hermit",
53+
all(target_vendor = "fortanix", target_env = "sgx"),
54+
target_os = "xous",
55+
target_os = "uefi",
56+
)) => {
5557
unsafe fn abort() -> ! {
5658
// call std::sys::abort_internal
5759
extern "C" {
5860
pub fn __rust_abort() -> !;
5961
}
6062
__rust_abort();
6163
}
62-
} else if #[cfg(all(windows, not(miri)))] {
64+
}
65+
cfg(all(windows, not(miri))) => {
6366
// On Windows, use the processor-specific __fastfail mechanism. In Windows 8
6467
// and later, this will terminate the process immediately without running any
6568
// in-process exception handlers. In earlier versions of Windows, this
@@ -86,7 +89,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
8689
}
8790
core::intrinsics::unreachable();
8891
}
89-
} else if #[cfg(target_os = "teeos")] {
92+
}
93+
cfg(target_os = "teeos") => {
9094
mod teeos {
9195
extern "C" {
9296
pub fn TEE_Panic(code: u32) -> !;
@@ -96,7 +100,8 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
96100
unsafe fn abort() -> ! {
97101
teeos::TEE_Panic(1);
98102
}
99-
} else {
103+
}
104+
_ => {
100105
unsafe fn abort() -> ! {
101106
core::intrinsics::abort();
102107
}

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,32 +32,37 @@ 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 = "xous",
5358
target_os = "solid_asp3",
5459
all(target_family = "unix", not(target_os = "espidf")),
5560
all(target_vendor = "fortanix", target_env = "sgx"),
56-
))] {
61+
)) => {
5762
#[path = "gcc.rs"]
5863
mod real_imp;
59-
} else {
64+
}
65+
_ => {
6066
// Targets that don't support unwinding.
6167
// - family=wasm
6268
// - os=none ("bare metal" targets)
@@ -69,14 +75,15 @@ cfg_if::cfg_if! {
6975
}
7076
}
7177

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

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
@@ -314,6 +314,7 @@
314314
//
315315
// Library features (core):
316316
// tidy-alphabetical-start
317+
#![feature(cfg_match)]
317318
#![feature(char_internals)]
318319
#![feature(core_intrinsics)]
319320
#![feature(core_io_borrowed_buf)]

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/pal/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)