about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2020-11-26 13:39:15 +0100
committerGitHub <noreply@github.com>2020-11-26 13:39:15 +0100
commiteb74eb7761d4322fdc7d23721269f9e817da2ab5 (patch)
tree0f0ccccfd206840c269a25686edeba8c3c80608b
parent7b723795ef7e5333c7c981b24aa827cf98e515f3 (diff)
parent1d587d8c4c6b7150131cbe1c421ee419dcb4c56d (diff)
downloadrust-eb74eb7761d4322fdc7d23721269f9e817da2ab5.tar.gz
rust-eb74eb7761d4322fdc7d23721269f9e817da2ab5.zip
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`
-rw-r--r--src/librustdoc/doctest.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 9f35e57df41..a615701f253 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -754,12 +754,14 @@ impl Tester for Collector {
             let folder_name = filename
                 .to_string()
                 .chars()
-                .map(|c| if c == '/' || c == '.' { '_' } else { c })
+                .map(|c| if c == '\\' || c == '/' || c == '.' { '_' } else { c })
                 .collect::<String>();
 
             path.push(format!(
-                "{name}_{line}_{number}",
-                name = folder_name,
+                "{krate}_{file}_{line}_{number}",
+                krate = cratename,
+                file = folder_name,
+                line = line,
                 number = {
                     // Increases the current test number, if this file already
                     // exists or it creates a new entry with a test number of 0.
@@ -768,7 +770,6 @@ impl Tester for Collector {
                         .and_modify(|v| *v += 1)
                         .or_insert(0)
                 },
-                line = line,
             ));
 
             std::fs::create_dir_all(&path)