Skip to content

cargo clean: do not error if explicitly specified target-dir does not exist#16934

Merged
weihanglo merged 2 commits intorust-lang:masterfrom
TanmayArya-1p:target-dir-noop
Apr 23, 2026
Merged

cargo clean: do not error if explicitly specified target-dir does not exist#16934
weihanglo merged 2 commits intorust-lang:masterfrom
TanmayArya-1p:target-dir-noop

Conversation

@TanmayArya-1p
Copy link
Copy Markdown
Contributor

Fixes #16925

Regressed in #16712 which added validation for explicitly specified target directories by checking if they contain a valid CACHEDIR.TAG.
This PR makes it so that cargo skips this validation if the target-dir doesn't exist.

@TanmayArya-1p TanmayArya-1p marked this pull request as ready for review April 23, 2026 14:32
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 23, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Comment thread src/cargo/ops/cargo_clean.rs Outdated
Comment on lines +77 to +79
if target_dir_path.exists() {
// check if the target directory has a valid CACHEDIR.TAG
if let Err(err) = validate_target_dir_tag(target_dir_path) {
Copy link
Copy Markdown
Member

@weihanglo weihanglo Apr 23, 2026

Choose a reason for hiding this comment

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

nit: we can collapse this with if-let chain maybe?

Suggested change
if target_dir_path.exists() {
// check if the target directory has a valid CACHEDIR.TAG
if let Err(err) = validate_target_dir_tag(target_dir_path) {
// and check if the target directory has a valid CACHEDIR.TAG
if target_dir_path.exists() && let Err(err) = validate_target_dir_tag(target_dir_path) {

View changes since the review

@weihanglo
Copy link
Copy Markdown
Member

Thanks!

@weihanglo weihanglo enabled auto-merge April 23, 2026 20:03
@weihanglo weihanglo added this pull request to the merge queue Apr 23, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 23, 2026
@weihanglo weihanglo added this pull request to the merge queue Apr 23, 2026
Merged via the queue into rust-lang:master with commit a0fbe93 Apr 23, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 23, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Apr 25, 2026
Update cargo submodule

10 commits in 06ac0e7c05770a8c7bbf67bdd12fa1a1eefdc8ae..eb9b60f1f6604b5e022c56be31692c215b8ba11d
2026-04-21 15:33:56 +0000 to 2026-04-24 20:52:07 +0000
- chore: Remove unused deps (rust-lang/cargo#16938)
- feat(compile): Stabilize `build.warnings` (rust-lang/cargo#16796)
- cargo clean: do not error if explicitly specified target-dir does not exist (rust-lang/cargo#16934)
- Revert "feat(lints): Add unused deps ignore list" (rust-lang/cargo#16937)
- fix(compile): Ignore unused deps if also transitive  (rust-lang/cargo#16935)
- Update rustls (rust-lang/cargo#16932)
- chore(deps): update rust crate openssl to v0.10.78 [security] (rust-lang/cargo#16931)
- chore(build-rs): Ensure we lint the crate (rust-lang/cargo#16930)
- Fix flaky test: proc_macro_in_artifact_dep (rust-lang/cargo#16922)
- refactor(compile): Log all ignored unused externs (rust-lang/cargo#16920)

r? ghost
@rustbot rustbot added this to the 1.97.0 milestone Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo clean --target-dir fails when target dir doesn't exist

3 participants