about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-06-13 18:43:53 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-08-13 20:14:54 +0200
commitdcc77b4cbcaf94d5bca34680934c87d172a8d02f (patch)
tree24161f5b4c71d73bd99305651e644b6456b0dbfc
parentb6831bbdda3aa9ea3cc5e6d02a75f93c025818d4 (diff)
downloadrust-dcc77b4cbcaf94d5bca34680934c87d172a8d02f.tar.gz
rust-dcc77b4cbcaf94d5bca34680934c87d172a8d02f.zip
Fix weird memory allocation failure in merged doctests by storing doctest list into a const
-rw-r--r--src/librustdoc/doctest/runner.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/librustdoc/doctest/runner.rs b/src/librustdoc/doctest/runner.rs
index 1a4a375aa16..3f1ab7208f2 100644
--- a/src/librustdoc/doctest/runner.rs
+++ b/src/librustdoc/doctest/runner.rs
@@ -45,11 +45,11 @@ impl DocTestRunner {
                 self.crate_attrs.insert(line.to_string());
             }
         }
-        // if !self.ids.is_empty() {
-        //     self.ids.push(',');
-        // }
+        if !self.ids.is_empty() {
+            self.ids.push(',');
+        }
         self.ids.push_str(&format!(
-            "tests.push({}::TEST);\n",
+            "{}::TEST",
             generate_mergeable_doctest(
                 doctest,
                 scraped_test,
@@ -107,14 +107,14 @@ impl DocTestRunner {
 #[rustc_main]
 #[coverage(off)]
 fn main() {{
-let mut tests = Vec::new();
-{ids}
+const TESTS: [test::TestDescAndFn; {nb_tests}] = [{ids}];
 test::test_main(
     &[{test_args}],
-    tests,
+    Vec::from(TESTS),
     None,
 );
 }}",
+            nb_tests = self.nb_tests,
             output = self.output,
             ids = self.ids,
         )
@@ -192,7 +192,7 @@ pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
         compile_fail: false,
         no_run: {no_run},
         should_panic: test::ShouldPanic::{should_panic},
-        test_type: test::TestType::UnitTest,
+        test_type: test::TestType::DocTest,
     }},
     testfn: test::StaticTestFn(
         #[coverage(off)]