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

Merged
merged 3 commits into from
Aug 18, 2025
Merged

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
bors added a commit that referenced this pull request Aug 18, 2025
Rollup of 19 pull requests

Successful merges:

 - #140956 (`impl PartialEq<{str,String}> for {Path,PathBuf}`)
 - #141744 (Stabilize `ip_from`)
 - #144804 (Don't warn on never to any `as` casts as unreachable)
 - #144983 (Rehome 37 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - #145025 (run spellcheck as a tidy extra check in ci)
 - #145041 (rework GAT borrowck limitation error)
 - #145243 (take attr style into account in diagnostics)
 - #145359 (Fix bug where `rustdoc-js` tester would not pick the right `search.js` file if there is more than one)
 - #145429 (Couple of codegen_fn_attrs improvements)
 - #145452 (Do not strip binaries in bootstrap everytime if they are unchanged)
 - #145486 (Fix `unicode_data.rs` mention message)
 - #145489 (library: Migrate from `cfg_if` to `cfg_select`)
 - #145493 (remove `should_render` in `PrintAttribute` derive)
 - #145500 (Port must_use to the new target checking)
 - #145505 (Simplify span caches)
 - #145511 (Rust build fails on OpenBSD after using file_lock feature)
 - #145516 (Weekly `cargo update`)
 - #145533 (Reorder `lto` options from most to least optimizing)
 - #145550 (Avoid using `()` in `derive(From)` output.)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 18, 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
Copy link
Collaborator

bors commented Aug 18, 2025

⌛ Testing commit c44c1bb with merge 9eb4a26...

@bors
Copy link
Collaborator

bors commented Aug 18, 2025

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 9eb4a26 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 18, 2025
@bors bors merged commit 9eb4a26 into rust-lang:master Aug 18, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 18, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing aaf87a6 (parent) -> 9eb4a26 (this PR)

Test differences

Show 85 test diffs

85 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 9eb4a2652031ed5ba97c29ef21c79db1645f7883 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-apple: 8343.8s -> 6230.8s (-25.3%)
  2. x86_64-mingw-1: 10076.4s -> 12352.6s (22.6%)
  3. dist-apple-various: 6812.6s -> 5320.5s (-21.9%)
  4. dist-aarch64-msvc: 5308.7s -> 6124.9s (15.4%)
  5. dist-x86_64-apple: 12572.4s -> 11116.5s (-11.6%)
  6. i686-msvc-1: 10349.9s -> 11528.9s (11.4%)
  7. x86_64-msvc-2: 7045.2s -> 7803.7s (10.8%)
  8. x86_64-apple-1: 8238.2s -> 9093.2s (10.4%)
  9. i686-msvc-2: 7836.4s -> 8580.8s (9.5%)
  10. x86_64-msvc-1: 9157.6s -> 9955.7s (8.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9eb4a26): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 9
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.2% [-1.2%, -1.2%] 1

Max RSS (memory usage)

Results (primary 4.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
4.4% [4.4%, 4.4%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.4% [4.4%, 4.4%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (secondary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 472.035s -> 469.299s (-0.58%)
Artifact size: 377.77 MiB -> 377.68 MiB (-0.02%)

@rustbot rustbot added the perf-regression Performance regression. label Aug 19, 2025
@joshtriplett joshtriplett deleted the cfg-if-not branch August 19, 2025 07:58
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Aug 19, 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.
joshtriplett added a commit to joshtriplett/rust that referenced this pull request Aug 19, 2025
rust-lang#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: rust-lang#145594
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 19, 2025
…=tgross35

`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`

rust-lang#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: rust-lang#145594
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 19, 2025
…=tgross35

`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`

rust-lang#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: rust-lang#145594
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 20, 2025
…=tgross35

`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`

rust-lang#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: rust-lang#145594
rust-timer added a commit that referenced this pull request Aug 20, 2025
Rollup merge of #145619 - joshtriplett:use-the-right-core, r=tgross35

`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`

#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: #145594
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 21, 2025
`std_detect`: Use `rustc-std-workspace-*` to pull in `compiler-builtins`

rust-lang/rust#145489 changed `std_detect` to no
longer depend on `cfg-if`, which meant it no longer indirectly pulled in
`rustc-std-workspace-core` via `cfg-if`. That caused it to no longer
depend on `compiler-builtins`.

Change `std_detect` to use `rustc-std-workspace-core` and
`rustc-std-workspace-alloc`, to integrate with the rustc workspace. This
also pulls in `compiler-builtins` via `rustc-std-workspace-core`.

Closes: rust-lang/rust#145594
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)]` merged-by-bors This PR was explicitly merged by bors. 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 perf-regression Performance regression. 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.

9 participants