refactor: cleanup for CompileMode#15608
Conversation
To justify why it won't affect any existing behavior:
* For the default set of Cargo targets,
test/bench targets would only be selected by `cargo test`,
whose UserIntent will turn into `CompileMode::Test`,
but never `CompileMode::Build`.
* For selective Cargo targets, i.e., `--tests`, or `--test`,
Their `CompileMode` would either be `Check { test }` or `Test`.
They will never be `Build`.
See https://github.com/rust-lang/cargo/blob/bffece899e9/src/cargo/ops/cargo_compile/unit_generator.rs#L450-L465
According to these facts, there won't be a case that
bench/test targets get assigned to `CompileMode::Build`.
They are globally determined at Cargo invocation level, and can all be derived from `UserIntent`.
CompileMode
`cargo test` will implicitly build examples as examples binaries (without --test) by default, when no target selection flags provided. We don't have test exercising this, so add one.
| /// * Like other test targets, it shouldn't respect profile panic settings. | ||
| /// This is for backward compatibility. Whether it is by design, not sure. |
There was a problem hiding this comment.
I believe this is intentional. I think the comment at
cargo/src/cargo/ops/cargo_compile/unit_generator.rs
Lines 106 to 125 in 2a8a85f
Overall I'm not so certain about this commit. Instead of checking in one place (at a low level), it pushes it to a higher level that requires checking in multiple places. There's also the risk that that could get missed in the future if there are other changes that would require checking for it.
Can you say more about what made you feel uncomfortable about checking it at the low level?
There was a problem hiding this comment.
Nah. Just felt it better to have one function finalizing everything, and the other do the conversion. But yeah it doesn't really make sense doing it in two places. Also, new_units is not a public function, and a regression test is added, so should be fine without this commit.
Removed!
Update cargo 12 commits in 68db37499f2de8acef704c73d9031be6fbcbaee4..64a12460708cf146e16cc61f28aba5dc2463bbb4 2025-05-22 14:27:15 +0000 to 2025-05-30 18:25:08 +0000 - chore: remove HTML comments and inline guide (rust-lang/cargo#15613) - Add .git-blame-ignore-revs (rust-lang/cargo#15612) - refactor: cleanup for `CompileMode` (rust-lang/cargo#15608) - refactor: separate "global" mode from CompileMode (rust-lang/cargo#15601) - fix(doc): pass `toolchain-shared-resources` to get doc styled (rust-lang/cargo#15605) - fix(embedded): Resolve multiple bugs in frontmatter parser (rust-lang/cargo#15573) - chore: Upgrade schemars (rust-lang/cargo#15602) - Update gix & socket2 (rust-lang/cargo#15600) - Add `-Zfix-edition` (rust-lang/cargo#15596) - chore(toml): disable `toml`'s default features, unless necessary (rust-lang/cargo#15598) - docs(README): fix the link to the changelog in the Cargo book (rust-lang/cargo#15597) - Add the future edition (rust-lang/cargo#15595) r? ghost
Update cargo 12 commits in 68db37499f2de8acef704c73d9031be6fbcbaee4..64a12460708cf146e16cc61f28aba5dc2463bbb4 2025-05-22 14:27:15 +0000 to 2025-05-30 18:25:08 +0000 - chore: remove HTML comments and inline guide (rust-lang/cargo#15613) - Add .git-blame-ignore-revs (rust-lang/cargo#15612) - refactor: cleanup for `CompileMode` (rust-lang/cargo#15608) - refactor: separate "global" mode from CompileMode (rust-lang/cargo#15601) - fix(doc): pass `toolchain-shared-resources` to get doc styled (rust-lang/cargo#15605) - fix(embedded): Resolve multiple bugs in frontmatter parser (rust-lang/cargo#15573) - chore: Upgrade schemars (rust-lang/cargo#15602) - Update gix & socket2 (rust-lang/cargo#15600) - Add `-Zfix-edition` (rust-lang/cargo#15596) - chore(toml): disable `toml`'s default features, unless necessary (rust-lang/cargo#15598) - docs(README): fix the link to the changelog in the Cargo book (rust-lang/cargo#15597) - Add the future edition (rust-lang/cargo#15595) r? ghost
What does this PR try to resolve?
Some more cleanup after #15601
See each commit message for details.
How should we test and review this PR?
Help review whether it has really no behavior change.