From e5f15a71e8eb07eb93fb3946c881b1a8dc12edae Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Thu, 13 Aug 2026 23:25:40 +0900 Subject: [PATCH 1/2] test: Extend unremap_file_with_cargo_clean to test new build-dir layout --- tests/testsuite/profile_trim_paths.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index 955c2df8b8d..775a613d66a 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -1844,6 +1844,26 @@ fn unremap_file_with_cargo_clean() { assert!(!unremap_file_path(&p.bin("foo")).exists()); assert_eq!(p.glob("target/**/*.trim-paths.jsonl").count(), 0); + + // Test the new layout + + p.cargo("clean -Ztrim-paths") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .run(); + + p.cargo("build -Ztrim-paths -Zbuild-dir-new-layout") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .run(); + + assert!(unremap_file_path(&p.bin("foo")).exists()); + assert_eq!(p.glob("target/**/*.trim-paths.jsonl").count(), 2); + + p.cargo("clean -p foo -Ztrim-paths -Zbuild-dir-new-layout") + .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) + .run(); + + assert!(unremap_file_path(&p.bin("foo")).exists()); + assert_eq!(p.glob("target/**/*.trim-paths.jsonl").count(), 1); } // MSVC always emits a PDB when debuginfo is on (which the unremap file requires), From 461e4e968b8f9e3fa84210242fcf20c5bcb476e1 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Thu, 13 Aug 2026 23:27:32 +0900 Subject: [PATCH 2/2] fix: Remove unremap file when running cargo clean -p in new build-dir layout --- src/ops/cargo_clean.rs | 5 +++++ tests/testsuite/profile_trim_paths.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ops/cargo_clean.rs b/src/ops/cargo_clean.rs index fa3830775db..d7f4eb07b4c 100644 --- a/src/ops/cargo_clean.rs +++ b/src/ops/cargo_clean.rs @@ -322,6 +322,11 @@ fn clean_specs( .to_string_lossy() .into_owned(); + let uplifted_path = uplift_dir.join(&uplifted_filename); + // Unremap file emitted for `-Ztrim-paths`. + let unremap = trim_paths::append_unremap_suffix(&uplifted_path); + clean_ctx.rm_rf(&unremap)?; + dirs_to_clean.mark_utf(uplift_dir, |filename| { filename == uplifted_filename || filename == dep_info }); diff --git a/tests/testsuite/profile_trim_paths.rs b/tests/testsuite/profile_trim_paths.rs index 775a613d66a..39a90ef2d0b 100644 --- a/tests/testsuite/profile_trim_paths.rs +++ b/tests/testsuite/profile_trim_paths.rs @@ -1862,8 +1862,8 @@ fn unremap_file_with_cargo_clean() { .masquerade_as_nightly_cargo(&["-Ztrim-paths"]) .run(); - assert!(unremap_file_path(&p.bin("foo")).exists()); - assert_eq!(p.glob("target/**/*.trim-paths.jsonl").count(), 1); + assert!(!unremap_file_path(&p.bin("foo")).exists()); + assert_eq!(p.glob("target/**/*.trim-paths.jsonl").count(), 0); } // MSVC always emits a PDB when debuginfo is on (which the unremap file requires),