]> git.lizzy.rs Git - rust.git/commitdiff
Fix persisted doctests on Windows / when using workspaces
authorArpad Borsos <arpad.borsos@googlemail.com>
Wed, 25 Nov 2020 14:40:13 +0000 (15:40 +0100)
committerArpad Borsos <arpad.borsos@googlemail.com>
Wed, 25 Nov 2020 14:40:13 +0000 (15:40 +0100)
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`

src/librustdoc/doctest.rs

index 9f35e57df418b36f7cf6b5f287eca9c5a83f4f97..a615701f253d322b7fa3767571bf183649d946a7 100644 (file)
@@ -754,12 +754,14 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
             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 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
                         .and_modify(|v| *v += 1)
                         .or_insert(0)
                 },
-                line = line,
             ));
 
             std::fs::create_dir_all(&path)