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 955c2df8b8d..39a90ef2d0b 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(), 0); } // MSVC always emits a PDB when debuginfo is on (which the unremap file requires),