Skip to content

Commit 8db3293

Browse files
committed
Use cfg_select!
1 parent af41d11 commit 8db3293

20 files changed

Lines changed: 133 additions & 163 deletions

File tree

‎Cargo.lock‎

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

‎Cargo.toml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ rustpython-pylib = { workspace = true, optional = true }
3636
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
3737
rustpython-vm = { workspace = true, features = ["compiler", "gc"] }
3838

39-
cfg-if = { workspace = true }
4039
log = { workspace = true }
4140
flame = { workspace = true, optional = true }
4241

@@ -136,7 +135,7 @@ exclude = ["pymath"]
136135
version = "0.5.0"
137136
authors = ["RustPython Team"]
138137
edition = "2024"
139-
rust-version = "1.93.0"
138+
rust-version = "1.95.0"
140139
repository = "https://github.com/RustPython/RustPython"
141140
license = "MIT"
142141

@@ -176,7 +175,6 @@ ascii = "1.1"
176175
bitflags = "2.11.0"
177176
bitflagset = "0.0.3"
178177
bstr = "1"
179-
cfg-if = "1.0"
180178
chrono = { version = "0.4.44", default-features = false, features = ["clock", "oldtime", "std"] }
181179
constant_time_eq = "0.4"
182180
criterion = { version = "0.8", features = ["html_reports"] }

‎crates/common/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ rustpython-wtf8 = { workspace = true }
2020

2121
ascii = { workspace = true }
2222
bitflags = { workspace = true }
23-
cfg-if = { workspace = true }
2423
getrandom = { workspace = true }
2524
itertools = { workspace = true }
2625
libc = { workspace = true }

‎crates/common/src/lock.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use lock_api::{
66
RwLockReadGuard, RwLockUpgradableReadGuard, RwLockWriteGuard,
77
};
88

9-
cfg_if::cfg_if! {
10-
if #[cfg(feature = "threading")] {
9+
cfg_select! {
10+
feature = "threading" => {
1111
pub use parking_lot::{RawMutex, RawRwLock, RawThreadId};
12-
1312
pub use std::sync::OnceLock as OnceCell;
1413
pub use core::cell::LazyCell;
15-
} else {
14+
}
15+
_ => {
1616
mod cell_lock;
1717
pub use cell_lock::{RawCellMutex as RawMutex, RawCellRwLock as RawRwLock, SingleThreadId as RawThreadId};
1818

@@ -23,10 +23,11 @@ cfg_if::cfg_if! {
2323
// LazyLock: uses std::sync::LazyLock when std is available (even without
2424
// threading, because Rust test runner uses parallel threads).
2525
// Without std, uses a LazyCell wrapper (truly single-threaded only).
26-
cfg_if::cfg_if! {
27-
if #[cfg(any(feature = "threading", feature = "std"))] {
26+
cfg_select! {
27+
any(feature = "threading", feature = "std") => {
2828
pub use std::sync::LazyLock;
29-
} else {
29+
}
30+
_ => {
3031
pub struct LazyLock<T, F = fn() -> T>(core::cell::LazyCell<T, F>);
3132
// SAFETY: This branch is only active when both "std" and "threading"
3233
// features are absent — i.e., truly single-threaded no_std environments

‎crates/stdlib/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ ruff_source_file = { workspace = true }
3838

3939
ahash = { workspace = true }
4040
ascii = { workspace = true }
41-
cfg-if = { workspace = true }
4241
crossbeam-utils = { workspace = true }
4342
flame = { workspace = true, optional = true }
4443
hex = { workspace = true }

‎crates/stdlib/src/openssl.rs‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ mod cert;
77
mod ssl_error;
88

99
// Conditional compilation for OpenSSL version-specific error codes
10-
cfg_if::cfg_if! {
11-
if #[cfg(ossl310)] {
12-
// OpenSSL 3.1.0+
10+
cfg_select! {
11+
// OpenSSL 3.1.0+
12+
ossl310 => {
1313
mod ssl_data_31;
1414
use ssl_data_31 as ssl_data;
15-
} else if #[cfg(ossl300)] {
16-
// OpenSSL 3.0.0+
15+
}
16+
// OpenSSL 3.0.0+
17+
ossl300 => {
1718
mod ssl_data_300;
1819
use ssl_data_300 as ssl_data;
19-
} else {
20-
// OpenSSL 1.1.1+ (fallback)
20+
}
21+
// OpenSSL 1.1.1+ (fallback)
22+
_ => {
2123
mod ssl_data_111;
2224
use ssl_data_111 as ssl_data;
2325
}
@@ -30,11 +32,12 @@ use rustpython_common::lock::LazyLock;
3032

3133
// define our own copy of ProbeResult so we can handle the vendor case
3234
// easily, without having to have a bunch of cfgs
33-
cfg_if::cfg_if! {
34-
if #[cfg(openssl_vendored)] {
35-
static PROBE: LazyLock<ProbeResult> = LazyLock::new(openssl_probe::probe);
36-
} else {
37-
static PROBE: LazyLock<ProbeResult> = LazyLock::new(|| ProbeResult { cert_file: None, cert_dir: vec![] });
35+
static PROBE: LazyLock<ProbeResult> = cfg_select! {
36+
openssl_vendored => {
37+
LazyLock::new(openssl_probe::probe);
38+
}
39+
_ => {
40+
LazyLock::new(|| ProbeResult { cert_file: None, cert_dir: vec![] });
3841
}
3942
}
4043

@@ -1349,13 +1352,14 @@ mod _ssl {
13491352

13501353
#[pymethod]
13511354
fn set_default_verify_paths(&self, vm: &VirtualMachine) -> PyResult<()> {
1352-
cfg_if::cfg_if! {
1353-
if #[cfg(openssl_vendored)] {
1355+
cfg_select! {
1356+
openssl_vendored => {
13541357
let (cert_file, cert_dir) = get_cert_file_dir();
13551358
self.builder()
13561359
.load_verify_locations(Some(cert_file), Some(cert_dir))
13571360
.map_err(|e| convert_openssl_error(vm, e))
1358-
} else {
1361+
}
1362+
_ => {
13591363
self.builder()
13601364
.set_default_verify_paths()
13611365
.map_err(|e| convert_openssl_error(vm, e))

‎crates/stdlib/src/resource.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ mod resource {
1212
use core::mem;
1313
use std::io;
1414

15-
cfg_if::cfg_if! {
16-
if #[cfg(target_os = "android")] {
17-
#[expect(deprecated)]
18-
const RLIM_NLIMITS: i32 = libc::RLIM_NLIMITS;
19-
} else {
15+
#[cfg_attr(target_os = "android", expect(deprecated))]
16+
const RLIM_NLIMITS: i32 = cfg_select! {
17+
target_os = "android" => {
18+
libc::RLIM_NLIMITS
19+
}
20+
_ => {
2021
// This constant isn't abi-stable across os versions, so we just
2122
// pick a high number so we don't get false positive ValueErrors and just bubble up the
2223
// EINVAL that get/setrlimit return on an invalid resource
23-
const RLIM_NLIMITS: i32 = 256;
24+
256
2425
}
25-
}
26+
};
2627

2728
// TODO: RLIMIT_OFILE,
2829
#[pyattr]

‎crates/stdlib/src/socket.rs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,20 +1568,23 @@ mod _socket {
15681568
if socket_kind == -1 {
15691569
socket_kind = sock.r#type().map_err(|e| e.into_pyexception(vm))?.into();
15701570
}
1571-
cfg_if::cfg_if! {
1572-
if #[cfg(any(
1571+
1572+
cfg_select! {
1573+
any(
15731574
target_os = "android",
15741575
target_os = "freebsd",
15751576
target_os = "fuchsia",
15761577
target_os = "linux",
1577-
))] {
1578+
) => {
15781579
if proto == -1 {
15791580
proto = sock.protocol()?.map_or(0, Into::into);
15801581
}
1581-
} else {
1582+
}
1583+
_ => {
15821584
proto = 0;
15831585
}
15841586
}
1587+
15851588
return Ok(zelf.init_inner(family, socket_kind, proto, sock)?);
15861589
}
15871590

@@ -3259,14 +3262,9 @@ mod _socket {
32593262
}
32603263

32613264
fn sock_from_raw(fileno: RawSocket, vm: &VirtualMachine) -> PyResult<Socket> {
3262-
let invalid = {
3263-
cfg_if::cfg_if! {
3264-
if #[cfg(windows)] {
3265-
fileno == INVALID_SOCKET
3266-
} else {
3267-
fileno < 0
3268-
}
3269-
}
3265+
let invalid = cfg_select! {
3266+
windows => fileno == INVALID_SOCKET,
3267+
_ => fileno < 0
32703268
};
32713269
if invalid {
32723270
return Err(vm.new_value_error("negative file descriptor"));

‎crates/vm/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ ascii = { workspace = true }
4646
ahash = { workspace = true }
4747
bitflags = { workspace = true }
4848
bstr = { workspace = true }
49-
cfg-if = { workspace = true }
5049
crossbeam-utils = { workspace = true }
5150
chrono = { workspace = true }
5251
constant_time_eq = { workspace = true }

‎crates/vm/src/builtins/type.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ impl<T> AsRef<T> for PointerSlot<T> {
397397

398398
pub type PyTypeRef = PyRef<PyType>;
399399

400-
cfg_if::cfg_if! {
401-
if #[cfg(feature = "threading")] {
400+
cfg_select! {
401+
feature = "threading" => {
402402
unsafe impl Send for PyType {}
403403
unsafe impl Sync for PyType {}
404404
}

0 commit comments

Comments
 (0)