Skip to content

Commit 0b31e39

Browse files
committed
use cfg_select instead of cfg_if
1 parent f92d9c7 commit 0b31e39

11 files changed

Lines changed: 114 additions & 110 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ jobs:
259259
with:
260260
submodules: true
261261
- name: Install Rust
262-
run: rustup update 1.88.0 --no-self-update && rustup default 1.88.0
262+
run: rustup update 1.95 --no-self-update && rustup default 1.95
263263
- run: cargo build
264264

265265
miri:

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ autoexamples = true
1414
autotests = true
1515
edition = "2024"
1616
exclude = ["/ci/"]
17-
rust-version = "1.88.0"
17+
rust-version = "1.95"
1818

1919
[workspace]
2020
members = ['crates/cpp_smoke_test', 'crates/as-if-std']
@@ -26,7 +26,6 @@ exclude = [
2626
]
2727

2828
[dependencies]
29-
cfg-if = "1.0"
3029
rustc-demangle = "0.1.27"
3130

3231
# Optionally enable the ability to serialize a `Backtrace`, controlled through
@@ -48,7 +47,7 @@ addr2line = { version = "0.25.0", default-features = false }
4847
libc = { version = "0.2.156", default-features = false }
4948

5049
[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies.object]
51-
version = "0.39.0"
50+
version = "0.39.1"
5251
default-features = false
5352
features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive']
5453

crates/as-if-std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ doctest = false
1212
bench = false
1313

1414
[dependencies]
15-
cfg-if = "1.0"
1615
rustc-demangle = "0.1.27"
1716
libc = { version = "0.2.156", default-features = false }
1817

src/backtrace/libunwind.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ mod uw {
177177
) -> _Unwind_Reason_Code;
178178
}
179179

180-
cfg_if::cfg_if! {
180+
cfg_select! {
181181
// available since GCC 4.2.0, should be fine for our purpose
182-
if #[cfg(all(
182+
all(
183183
not(all(target_os = "android", target_arch = "arm")),
184184
not(all(target_os = "freebsd", target_arch = "arm")),
185185
not(all(target_os = "linux", target_arch = "arm")),
186186
not(all(target_os = "horizon", target_arch = "arm")),
187187
not(all(target_os = "rtems", target_arch = "arm")),
188188
not(all(target_os = "vita", target_arch = "arm")),
189189
not(all(target_os = "nuttx", target_arch = "arm")),
190-
))] {
190+
) => {
191191
unsafe extern "C" {
192192
pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t;
193193
pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;
@@ -213,7 +213,8 @@ mod uw {
213213
}
214214
unsafe { _Unwind_GetGR(ctx, 15) }
215215
}
216-
} else {
216+
}
217+
_ => {
217218
use core::ptr::addr_of_mut;
218219

219220
// On android and arm, the function `_Unwind_GetIP` and a bunch of

src/backtrace/mod.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,42 +163,44 @@ mod sgx_image_base {
163163
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
164164
pub use sgx_image_base::imp::set_image_base;
165165

166-
cfg_if::cfg_if! {
166+
cfg_select! {
167167
// This needs to come first, to ensure that
168168
// Miri takes priority over the host platform
169-
if #[cfg(miri)] {
169+
miri => {
170170
pub(crate) mod miri;
171171
use self::miri::trace as trace_imp;
172172
pub(crate) use self::miri::Frame as FrameImp;
173-
} else if #[cfg(
174-
any(
175-
all(
176-
unix,
177-
not(target_os = "emscripten"),
178-
not(all(target_os = "ios", target_arch = "arm")),
179-
),
180-
all(
181-
target_env = "sgx",
182-
target_vendor = "fortanix",
183-
),
184-
)
185-
)] {
173+
}
174+
any(
175+
all(
176+
unix,
177+
not(target_os = "emscripten"),
178+
not(all(target_os = "ios", target_arch = "arm")),
179+
),
180+
all(
181+
target_env = "sgx",
182+
target_vendor = "fortanix",
183+
),
184+
) => {
186185
mod libunwind;
187186
use self::libunwind::trace as trace_imp;
188187
pub(crate) use self::libunwind::Frame as FrameImp;
189-
} else if #[cfg(all(windows, not(target_vendor = "uwp")))] {
190-
cfg_if::cfg_if! {
191-
if #[cfg(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "arm64ec"))] {
188+
}
189+
all(windows, not(target_vendor = "uwp")) => {
190+
cfg_select! {
191+
any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "arm64ec") => {
192192
mod win64;
193193
use self::win64::trace as trace_imp;
194194
pub(crate) use self::win64::Frame as FrameImp;
195-
} else if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
195+
}
196+
any(target_arch = "x86", target_arch = "arm") => {
196197
mod win32;
197198
use self::win32::trace as trace_imp;
198199
pub(crate) use self::win32::Frame as FrameImp;
199200
}
200201
}
201-
} else {
202+
}
203+
_ => {
202204
mod noop;
203205
use self::noop::trace as trace_imp;
204206
pub(crate) use self::noop::Frame as FrameImp;

src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,18 @@ pub use self::symbolize::clear_symbol_cache;
121121
mod print;
122122
pub use print::{BacktraceFmt, BacktraceFrameFmt, PrintFmt};
123123

124-
cfg_if::cfg_if! {
125-
if #[cfg(feature = "std")] {
124+
cfg_select! {
125+
feature = "std" => {
126126
pub use self::backtrace::trace;
127127
pub use self::symbolize::{resolve, resolve_frame};
128128
pub use self::capture::{Backtrace, BacktraceFrame, BacktraceSymbol};
129129
mod capture;
130130
}
131+
_ => {}
131132
}
132133

133-
cfg_if::cfg_if! {
134-
if #[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))] {
135-
pub use self::backtrace::set_image_base;
136-
}
137-
}
134+
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
135+
pub use self::backtrace::set_image_base;
138136

139137
#[cfg(feature = "std")]
140138
mod lock {

src/symbolize/gimli.rs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ mod mystd {
2525
#[cfg(not(backtrace_in_libstd))]
2626
extern crate std as mystd;
2727

28-
cfg_if::cfg_if! {
29-
if #[cfg(windows)] {
28+
cfg_select! {
29+
windows => {
3030
#[path = "gimli/mmap_windows.rs"]
3131
mod mmap;
32-
} else if #[cfg(target_vendor = "apple")] {
33-
#[path = "gimli/mmap_unix.rs"]
34-
mod mmap;
35-
} else if #[cfg(any(
32+
}
33+
any(
34+
target_vendor = "apple",
3635
target_os = "android",
3736
target_os = "freebsd",
3837
target_os = "fuchsia",
@@ -44,10 +43,11 @@ cfg_if::cfg_if! {
4443
target_os = "illumos",
4544
target_os = "aix",
4645
target_os = "cygwin",
47-
))] {
46+
) => {
4847
#[path = "gimli/mmap_unix.rs"]
4948
mod mmap;
50-
} else {
49+
}
50+
_ => {
5151
#[path = "gimli/mmap_fake.rs"]
5252
mod mmap;
5353
}
@@ -195,33 +195,39 @@ fn mmap(path: &Path) -> Option<Mmap> {
195195
unsafe { Mmap::map(&file, len, 0) }
196196
}
197197

198-
cfg_if::cfg_if! {
199-
if #[cfg(any(windows, target_os = "cygwin"))] {
198+
cfg_select! {
199+
any(windows, target_os = "cygwin") => {
200200
mod coff;
201201
use self::coff::{handle_split_dwarf, Object};
202-
} else if #[cfg(any(target_vendor = "apple"))] {
202+
}
203+
target_vendor = "apple" => {
203204
mod macho;
204205
use self::macho::{handle_split_dwarf, Object};
205-
} else if #[cfg(target_os = "aix")] {
206+
}
207+
target_os = "aix" => {
206208
mod xcoff;
207209
use self::xcoff::{handle_split_dwarf, Object};
208-
} else {
210+
}
211+
_ => {
209212
mod elf;
210213
use self::elf::{handle_split_dwarf, Object};
211214
}
212215
}
213216

214-
cfg_if::cfg_if! {
215-
if #[cfg(any(windows, target_os = "cygwin"))] {
217+
cfg_select! {
218+
any(windows, target_os = "cygwin") => {
216219
mod libs_windows;
217220
use libs_windows::native_libraries;
218-
} else if #[cfg(target_vendor = "apple")] {
221+
}
222+
target_vendor = "apple" => {
219223
mod libs_macos;
220224
use libs_macos::native_libraries;
221-
} else if #[cfg(target_os = "illumos")] {
225+
}
226+
target_os = "illumos" => {
222227
mod libs_illumos;
223228
use libs_illumos::native_libraries;
224-
} else if #[cfg(all(
229+
}
230+
all(
225231
any(
226232
target_os = "linux",
227233
target_os = "fuchsia",
@@ -233,22 +239,26 @@ cfg_if::cfg_if! {
233239
target_os = "android",
234240
),
235241
not(target_env = "uclibc"),
236-
))] {
242+
) => {
237243
mod libs_dl_iterate_phdr;
238244
use libs_dl_iterate_phdr::native_libraries;
239245
#[path = "gimli/parse_running_mmaps_unix.rs"]
240246
mod parse_running_mmaps;
241-
} else if #[cfg(target_env = "libnx")] {
247+
}
248+
target_env = "libnx" => {
242249
mod libs_libnx;
243250
use libs_libnx::native_libraries;
244-
} else if #[cfg(target_os = "haiku")] {
251+
}
252+
target_os = "haiku" => {
245253
mod libs_haiku;
246254
use libs_haiku::native_libraries;
247-
} else if #[cfg(target_os = "aix")] {
255+
}
256+
target_os = "aix" => {
248257
mod libs_aix;
249258
use libs_aix::native_libraries;
250-
} else {
251-
// Everything else should doesn't know how to load native libraries.
259+
}
260+
_ => {
261+
// Everything else doesn't know how to load native libraries.
252262
fn native_libraries() -> Vec<Library> {
253263
Vec::new()
254264
}
@@ -316,12 +326,14 @@ struct LibrarySegment {
316326
}
317327

318328
fn create_mapping(lib: &Library) -> Option<Mapping> {
319-
cfg_if::cfg_if! {
320-
if #[cfg(target_os = "aix")] {
329+
cfg_select! {
330+
target_os = "aix" => {
321331
Mapping::new(lib.name.as_ref(), &lib.member_name)
322-
} else if #[cfg(target_os = "android")] {
332+
}
333+
target_os = "android" => {
323334
Mapping::new_android(lib.name.as_ref(), lib.zip_offset)
324-
} else {
335+
}
336+
_ => {
325337
Mapping::new(lib.name.as_ref())
326338
}
327339
}

src/symbolize/gimli/elf.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,22 @@ fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> {
397397
const DEBUG_PATH: &str = "/usr/lib/debug";
398398

399399
fn debug_path_exists() -> bool {
400-
cfg_if::cfg_if! {
401-
if #[cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux"))] {
402-
use core::sync::atomic::{AtomicU8, Ordering};
403-
static DEBUG_PATH_EXISTS: AtomicU8 = AtomicU8::new(0);
404-
405-
let mut exists = DEBUG_PATH_EXISTS.load(Ordering::Relaxed);
406-
if exists == 0 {
407-
exists = if Path::new(DEBUG_PATH).is_dir() {
408-
1
409-
} else {
410-
2
411-
};
412-
DEBUG_PATH_EXISTS.store(exists, Ordering::Relaxed);
413-
}
414-
exists == 1
415-
} else {
416-
false
400+
if cfg!(any(
401+
target_os = "freebsd",
402+
target_os = "hurd",
403+
target_os = "linux"
404+
)) {
405+
use core::sync::atomic::{AtomicU8, Ordering};
406+
static DEBUG_PATH_EXISTS: AtomicU8 = AtomicU8::new(0);
407+
408+
let mut exists = DEBUG_PATH_EXISTS.load(Ordering::Relaxed);
409+
if exists == 0 {
410+
exists = if Path::new(DEBUG_PATH).is_dir() { 1 } else { 2 };
411+
DEBUG_PATH_EXISTS.store(exists, Ordering::Relaxed);
417412
}
413+
exists == 1
414+
} else {
415+
false
418416
}
419417
}
420418

0 commit comments

Comments
 (0)