Use cfg_select! macro instead of cfg_if!#7636
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughRemoved Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
67f5ebc to
8db3293
Compare
April 20, 2026 13:12
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/vm/src/stdlib/posix.rs (1)
1805-1820: ⚠️ Potential issue | 🔴 CriticalRemove the stray
iffrom thecfg_select!arm.Line 1807 uses
if any(...) =>, but Rust 1.95cfg_select!arms use the cfg predicate directly without theifkeyword (any(...) =>). This is a compile-blocking syntax error. All othercfg_select!usages in the codebase follow the correct syntax withoutif.🐛 Proposed fix
// Note: POSIX_SPAWN_SETSID may not be available on all platforms cfg_select! { - if any( + any( target_os = "linux", target_os = "haiku", target_os = "solaris", target_os = "illumos", target_os = "hurd", ) => { flags.insert(nix::spawn::PosixSpawnFlags::from_bits_retain(libc::POSIX_SPAWN_SETSID));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/vm/src/stdlib/posix.rs` around lines 1805 - 1820, The cfg_select! arm in the flags handling block incorrectly uses the `if` keyword ("if any(...) =>") which is invalid syntax; edit the cfg_select! invocation (the block that inserts nix::spawn::PosixSpawnFlags::from_bits_retain(libc::POSIX_SPAWN_SETSID) and returns a new_not_implemented_error) to remove the stray `if` so the arm uses the predicate directly (e.g., `any(...) =>`), leaving the flags.insert(...) and the `_ => { return Err(vm.new_not_implemented_error(...)); }` arm unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/stdlib/src/openssl.rs`:
- Around line 35-42: The PROBE static initializer's cfg_select! branches end
with trailing semicolons making each branch evaluate to () instead of returning
a LazyLock<ProbeResult>; remove the semicolons after
LazyLock::new(openssl_probe::probe) and LazyLock::new(|| ProbeResult {
cert_file: None, cert_dir: vec![] }) so each branch yields a
LazyLock<ProbeResult> (affecting the PROBE static, the cfg_select! macro,
LazyLock::new invocations, and the ProbeResult construction).
In `@crates/vm/src/stdlib/_thread.rs`:
- Around line 34-39: The cfg_select! arms for PYTHREAD_NAME currently list the
broader unix => Some("pthread") arm before the more specific any(target_os =
"solaris", target_os = "illumos") arm, so Solaris/illumos targets never reach
their intended match; fix by reordering the cfg_select! arms in the
PYTHREAD_NAME constant so the any(target_os = "solaris", target_os = "illumos")
arm appears before the unix arm, preserving the other arms (windows and default)
as-is.
In `@crates/vm/src/stdlib/sys.rs`:
- Around line 248-255: The PLATFORM constant in sys.rs currently maps target_os
"macos" and Windows to non-CPython values; update the cfg_select! mapping in the
pub const PLATFORM definition so that target_os = "macos" => "darwin" and
windows => "win32" (leave the other arms unchanged) to match CPython's
sys.platform values; modify the PLATFORM const in crates/vm/src/stdlib/sys.rs
accordingly and run the build/tests to verify.
---
Outside diff comments:
In `@crates/vm/src/stdlib/posix.rs`:
- Around line 1805-1820: The cfg_select! arm in the flags handling block
incorrectly uses the `if` keyword ("if any(...) =>") which is invalid syntax;
edit the cfg_select! invocation (the block that inserts
nix::spawn::PosixSpawnFlags::from_bits_retain(libc::POSIX_SPAWN_SETSID) and
returns a new_not_implemented_error) to remove the stray `if` so the arm uses
the predicate directly (e.g., `any(...) =>`), leaving the flags.insert(...) and
the `_ => { return Err(vm.new_not_implemented_error(...)); }` arm unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 3c4d5dab-4eac-460c-b598-031fda07a667
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (19)
Cargo.tomlcrates/common/Cargo.tomlcrates/common/src/lock.rscrates/stdlib/Cargo.tomlcrates/stdlib/src/openssl.rscrates/stdlib/src/resource.rscrates/stdlib/src/socket.rscrates/vm/Cargo.tomlcrates/vm/src/builtins/type.rscrates/vm/src/macros.rscrates/vm/src/object/core.rscrates/vm/src/object/ext.rscrates/vm/src/object/payload.rscrates/vm/src/stdlib/_io.rscrates/vm/src/stdlib/_signal.rscrates/vm/src/stdlib/_thread.rscrates/vm/src/stdlib/os.rscrates/vm/src/stdlib/posix.rscrates/vm/src/stdlib/sys.rs
💤 Files with no reviewable changes (3)
- crates/common/Cargo.toml
- crates/vm/Cargo.toml
- crates/stdlib/Cargo.toml
Sorry, something went wrong.
8169811 to
7dce1bb
Compare
April 20, 2026 17:03
7dce1bb to
f446b28
Compare
April 20, 2026 18:17
coolreader18
left a comment
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
dc65255
into
RustPython:main
Apr 21, 2026
Since 1.95
cfg_select!macro is stabilizedhttps://doc.rust-lang.org/stable/std/macro.cfg_select.html
Summary by CodeRabbit
New Requirements
Chores
Clarification