Skip to content

Commit eb74eb7

Browse files
Rollup merge of #79413 - Swatinem:rustdoc-persist-crate, r=GuillaumeGomez
Fix persisted doctests on Windows / when using workspaces When using the unstable `--persist-doctests` option, Windows path separators were not escaped properly. Also when running the command in a workspace, crate files can overwrite each other. Before: `src\lib_rs_1_0\rust_out` After: `\crate_a_src_lib_rs_1_0\rust_out`, `\crate_b_src_lib_rs_1_0\rust_out`
2 parents 7b72379 + 1d587d8 commit eb74eb7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/librustdoc/doctest.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,14 @@ impl Tester for Collector {
754754
let folder_name = filename
755755
.to_string()
756756
.chars()
757-
.map(|c| if c == '/' || c == '.' { '_' } else { c })
757+
.map(|c| if c == '\\' || c == '/' || c == '.' { '_' } else { c })
758758
.collect::<String>();
759759

760760
path.push(format!(
761-
"{name}_{line}_{number}",
762-
name = folder_name,
761+
"{krate}_{file}_{line}_{number}",
762+
krate = cratename,
763+
file = folder_name,
764+
line = line,
763765
number = {
764766
// Increases the current test number, if this file already
765767
// exists or it creates a new entry with a test number of 0.
@@ -768,7 +770,6 @@ impl Tester for Collector {
768770
.and_modify(|v| *v += 1)
769771
.or_insert(0)
770772
},
771-
line = line,
772773
));
773774

774775
std::fs::create_dir_all(&path)

0 commit comments

Comments
 (0)