bootstrap: Prefer cfg!(not(test)) when skipping code paths during unit tests#159705
Conversation
|
This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp. This PR modifies If appropriate, please update This PR changes how GCC is built. Consider updating src/bootstrap/download-ci-gcc-stamp. |
|
r? @clubby789 rustbot has assigned @clubby789. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
The clippy false-positive for |
|
@bors r- |
|
This pull request was unapproved. |
Assertions have been added to some code paths that were previously not built during `cfg(test)`, to make sure they aren't accidentally executed.
|
I have pushed an update that allows (Allowing the individual asserts would be possible, but IMO the lint is pretty low-value so I don’t mind the blanket allow in this case.) @rustbot ready |
|
Yeah, agreed that the global allow is fine. I'll r+ once CI is green. |
|
@bors r+ rollup Thanks! |
bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests - [Zulip thread: Reducing conditional compilation in bootstrap?](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Reducing.20conditional.20compilation.20in.20bootstrap.3F/with/611882645) --- Bootstrap contains a few code paths that need to be stubbed out when running bootstrap's unit tests, so that they don't download files or cause other problems. (That's unfortunate, but fixing it is outside the scope of this PR.) Currently those code paths are skipped using `#[cfg(test)]` and `#[cfg(not(test))]`, which does achieve the desired effect, but has a few downsides. The stubbed-out code triggers dead-code and unused-import warnings, and makes IDE navigation harder when rust-analyzer treats `cfg(test)` as true when analyzing the code. If we switch to using `cfg!(test)` and `cfg!(not(test))` to “dynamically” skip the relevant code paths, it still gets skipped, but the skipped code is still considered live for the purpose of dead-code warnings and IDE analysis.
…uwer Rollup of 8 pull requests Successful merges: - #159712 (Subtree sync for rustc_codegen_cranelift) - #155697 (Stabilize c-variadic function definitions) - #159285 (Simplify `apply_effects_in_range`) - #159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes) - #159659 (Move `Limit` out of `rustc_hir`) - #159451 (Remove config cloning in compiletest) - #159646 (Increase depth for float infer var fallback hack) - #159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests - [Zulip thread: Reducing conditional compilation in bootstrap?](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Reducing.20conditional.20compilation.20in.20bootstrap.3F/with/611882645) --- Bootstrap contains a few code paths that need to be stubbed out when running bootstrap's unit tests, so that they don't download files or cause other problems. (That's unfortunate, but fixing it is outside the scope of this PR.) Currently those code paths are skipped using `#[cfg(test)]` and `#[cfg(not(test))]`, which does achieve the desired effect, but has a few downsides. The stubbed-out code triggers dead-code and unused-import warnings, and makes IDE navigation harder when rust-analyzer treats `cfg(test)` as true when analyzing the code. If we switch to using `cfg!(test)` and `cfg!(not(test))` to “dynamically” skip the relevant code paths, it still gets skipped, but the skipped code is still considered live for the purpose of dead-code warnings and IDE analysis.
…uwer Rollup of 12 pull requests Successful merges: - #159712 (Subtree sync for rustc_codegen_cranelift) - #155697 (Stabilize c-variadic function definitions) - #159285 (Simplify `apply_effects_in_range`) - #159596 (unify the AST repr of type const and const RHS) - #159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes) - #159659 (Move `Limit` out of `rustc_hir`) - #159707 (fix error when a dangling ref in a ManuallyDrop is used in a pattern) - #158479 (Reject static item as direct const generic arg) - #158738 (next_trait_solver: Recover from GCE const exprs) - #159451 (Remove config cloning in compiletest) - #159646 (Increase depth for float infer var fallback hack) - #159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
…uwer Rollup of 11 pull requests Successful merges: - #159712 (Subtree sync for rustc_codegen_cranelift) - #155697 (Stabilize c-variadic function definitions) - #159285 (Simplify `apply_effects_in_range`) - #159596 (unify the AST repr of type const and const RHS) - #159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes) - #159659 (Move `Limit` out of `rustc_hir`) - #159707 (fix error when a dangling ref in a ManuallyDrop is used in a pattern) - #158738 (next_trait_solver: Recover from GCE const exprs) - #159451 (Remove config cloning in compiletest) - #159646 (Increase depth for float infer var fallback hack) - #159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
Rollup merge of #159705 - Zalathar:cfg-test, r=Kobzol bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests - [Zulip thread: Reducing conditional compilation in bootstrap?](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Reducing.20conditional.20compilation.20in.20bootstrap.3F/with/611882645) --- Bootstrap contains a few code paths that need to be stubbed out when running bootstrap's unit tests, so that they don't download files or cause other problems. (That's unfortunate, but fixing it is outside the scope of this PR.) Currently those code paths are skipped using `#[cfg(test)]` and `#[cfg(not(test))]`, which does achieve the desired effect, but has a few downsides. The stubbed-out code triggers dead-code and unused-import warnings, and makes IDE navigation harder when rust-analyzer treats `cfg(test)` as true when analyzing the code. If we switch to using `cfg!(test)` and `cfg!(not(test))` to “dynamically” skip the relevant code paths, it still gets skipped, but the skipped code is still considered live for the purpose of dead-code warnings and IDE analysis.
…uwer Rollup of 11 pull requests Successful merges: - rust-lang/rust#159712 (Subtree sync for rustc_codegen_cranelift) - rust-lang/rust#155697 (Stabilize c-variadic function definitions) - rust-lang/rust#159285 (Simplify `apply_effects_in_range`) - rust-lang/rust#159596 (unify the AST repr of type const and const RHS) - rust-lang/rust#159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes) - rust-lang/rust#159659 (Move `Limit` out of `rustc_hir`) - rust-lang/rust#159707 (fix error when a dangling ref in a ManuallyDrop is used in a pattern) - rust-lang/rust#158738 (next_trait_solver: Recover from GCE const exprs) - rust-lang/rust#159451 (Remove config cloning in compiletest) - rust-lang/rust#159646 (Increase depth for float infer var fallback hack) - rust-lang/rust#159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
…uwer Rollup of 11 pull requests Successful merges: - rust-lang/rust#159712 (Subtree sync for rustc_codegen_cranelift) - rust-lang/rust#155697 (Stabilize c-variadic function definitions) - rust-lang/rust#159285 (Simplify `apply_effects_in_range`) - rust-lang/rust#159596 (unify the AST repr of type const and const RHS) - rust-lang/rust#159607 (test: update riscv32e-registers.rs for LLVM 24 MC diagnostic changes) - rust-lang/rust#159659 (Move `Limit` out of `rustc_hir`) - rust-lang/rust#159707 (fix error when a dangling ref in a ManuallyDrop is used in a pattern) - rust-lang/rust#158738 (next_trait_solver: Recover from GCE const exprs) - rust-lang/rust#159451 (Remove config cloning in compiletest) - rust-lang/rust#159646 (Increase depth for float infer var fallback hack) - rust-lang/rust#159705 (bootstrap: Prefer `cfg!(not(test))` when skipping code paths during unit tests)
Bootstrap contains a few code paths that need to be stubbed out when running bootstrap's unit tests, so that they don't download files or cause other problems. (That's unfortunate, but fixing it is outside the scope of this PR.)
Currently those code paths are skipped using
#[cfg(test)]and#[cfg(not(test))], which does achieve the desired effect, but has a few downsides. The stubbed-out code triggers dead-code and unused-import warnings, and makes IDE navigation harder when rust-analyzer treatscfg(test)as true when analyzing the code.If we switch to using
cfg!(test)andcfg!(not(test))to “dynamically” skip the relevant code paths, it still gets skipped, but the skipped code is still considered live for the purpose of dead-code warnings and IDE analysis.