Skip to content

library: Migrate from cfg_if to cfg_select #145489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

Migrate the standard library from using the external cfg_if crate to using the now-built-in cfg_select macro.

This does not yet eliminate the dependency from library/std/Cargo.toml, because while the standard library itself no longer uses cfg_if, it also incorporates the backtrace crate, which does.

Migration assisted by the following vim command (after selecting the full cfg_if! invocation):

'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e

This is imperfect, but substantially accelerated the process. This prompts for confirmation on the } else { since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.

@joshtriplett joshtriplett added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Aug 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2025
@rustbot

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
@jieyouxu jieyouxu added the F-cfg_select `#![feature(cfg_select)]` label Aug 16, 2025
@joshtriplett
Copy link
Member Author

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned Mark-Simulacrum Aug 16, 2025
Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

The previous code inside `cfg_if!` wasn't indented, so the conversion to
`cfg_select!` left it not indented. Indent it.
@joshtriplett
Copy link
Member Author

@bors r=Amanieu p=1
(Prone to conflicts.)

@bors
Copy link
Collaborator

bors commented Aug 17, 2025

📌 Commit bc9725c has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 17, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 17, 2025
library: Migrate from `cfg_if` to `cfg_select`

Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does.

Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
bors added a commit that referenced this pull request Aug 17, 2025
Rollup of 10 pull requests

Successful merges:

 - #144476 (rustdoc-search: search backend with partitioned suffix tree)
 - #144838 (Fix outdated doc comment)
 - #145206 (Port `#[custom_mir(..)]` to the new attribute system)
 - #145208 (Implement declarative (`macro_rules!`) derive macros (RFC 3698))
 - #145420 (cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind`)
 - #145451 (Add static glibc to the nix dev shell)
 - #145460 (Speedup `copy_src_dirs` in bootstrap)
 - #145476 (Fix typo in doc for library/std/src/fs.rs#set_permissions)
 - #145485 (Fix deprecation attributes on foreign statics)
 - #145489 (library: Migrate from `cfg_if` to `cfg_select`)

r? `@ghost`
`@rustbot` modify labels: rollup
@Zalathar
Copy link
Contributor

Failed in rollup: #145521 (comment)

@bors r-
@bors try jobs=x86_64-gnu-llvm-19-3

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 17, 2025
rust-bors bot added a commit that referenced this pull request Aug 17, 2025
library: Migrate from `cfg_if` to `cfg_select`

try-job: x86_64-gnu-llvm-19-3
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 17, 2025

💔 Test for b3311ae failed: CI. Failed jobs:

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Aug 17, 2025
@joshtriplett
Copy link
Member Author

@bors r=Amanieu rollup=iffy p=1

@bors
Copy link
Collaborator

bors commented Aug 17, 2025

📌 Commit c44c1bb has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs F-cfg_select `#![feature(cfg_select)]` O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants