fix(clean): respect build.target config for clean -p#16988
Conversation
|
r? @weihanglo rustbot has assigned @weihanglo. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Captures the current behavior where `cargo clean -p <pkg>` ignores the `build.target` config and reports 0 files, even though the build produced target-specific artifacts. See rust-lang#16974.
`clean_specs` resolves the requested kinds via `from_requested_targets`, which already falls back to `build.target` when no `--target` is passed. However, the layout selection then re-checked the raw CLI `targets` vec and dropped down to the host layout whenever `--target` was absent, ignoring the config fallback. Switch the check to `target_layouts.is_empty()` so a config-only target selects the target layouts, matching `--target` and the behavior documented for `cargo clean`. Fixes rust-lang#16974
There was a problem hiding this comment.
🔢 Self-check (PR reviewed by myself and ready for feedback)
-
Code compiles successfully
-
Unit tests added
-
No AI-generated elegant nonsense in PR.
-
Comments added where necessary
-
PR title and description updated
-
Documentation PR created (or confirmed not needed)
-
PR size is reasonable
There was a problem hiding this comment.
This is a reasonable fix, though it is changing the behavior of cargo clean with a slightly hard-to-notice way that people may not even realize they have configured build.target in the Cargo configuration file. We should probably put this under Cargo's own compatibility notice in Changelog
Thanks for the fix anyway.
Update cargo submodule 7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662 2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000 - Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999) - CI: update to macos-15 (rust-lang/cargo#16996) - fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988) - fix(diag): Consolidate verify/run diagnostics passes (rust-lang/cargo#16989) - fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981) - fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985) - Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965) r? ghost
Update cargo submodule 7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662 2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000 - Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999) - CI: update to macos-15 (rust-lang/cargo#16996) - fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988) - fix(diag): Consolidate verify/run diagnostics passes (rust-lang/cargo#16989) - fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981) - fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985) - Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965) r? ghost
Update cargo submodule 7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662 2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000 - Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999) - CI: update to macos-15 (rust-lang/cargo#16996) - fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988) - fix(diag): Consolidate verify/run diagnostics passes (rust-lang/cargo#16989) - fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981) - fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985) - Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965) r? ghost
Update cargo submodule 7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662 2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000 - Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999) - CI: update to macos-15 (rust-lang/cargo#16996) - fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988) - fix(diag): Consolidate verify/run diagnostics passes (rust-lang/cargo#16989) - fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981) - fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985) - Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965) r? ghost
Update cargo submodule 7 commits in a343accce8526b128adc517d33348573d22920a3..4d1f984518c77fad6eeef4f40153b002a659e662 2026-05-08 22:41:35 +0000 to 2026-05-15 17:12:01 +0000 - Revert "feat: add frame-pointers profile option (rust-lang/cargo#16742)" (rust-lang/cargo#16999) - CI: update to macos-15 (rust-lang/cargo#16996) - fix(clean): respect `build.target` config for `clean -p` (rust-lang/cargo#16988) - fix(diag): Consolidate verify/run diagnostics passes (rust-lang/cargo#16989) - fix(diag): Track Cargo diagnostic warning/error count like is done for rustc (rust-lang/cargo#16981) - fix: suggest 'fmt' when user types 'cargo rustfmt' (rust-lang/cargo#16985) - Rebuild when -Zpublic-dependency changes (rust-lang/cargo#16965) r? ghost
What does this PR try to resolve?
Fixes #16974.
cargo clean -pignoredbuild.targetconfig.clean_specsresolvesrequested_kindswith the config fallback, but the layout selection rechecked the raw CLItargetsvec instead. Switched to checkingtarget_layouts.is_empty().How should we test and review this PR?
Two commits: a test capturing the buggy
Summary 0 filesoutput, then a one-line fix that flips the test expectation.