Skip to content

Commit 649251f

Browse files
authored
Unrolled build for rust-lang#138281
Rollup merge of rust-lang#138281 - saethlin:mergeable-doctests-stacksize, r=GuillaumeGomez Fix O(tests) stack usage in edition 2024 mergeable doctests Fixes rust-lang#138248 The important change here is that we are not passing a potentially-large array by value. Between the fact that `TestFn` cannot be `Clone` and `test_main` takes a `Vec<TestDescAndFn>`, the only way to call `test::test_main` without O(tests) stack use is to call `Vec::push` many times. The normal test harness does not have this problem because it calls `test_main_static` or `test_main_static_abort`, which take `&[TestDescAndFn]`. Changing `test::test_main` to take a slice is not a simple change, so I'm avoiding doing it here.
2 parents 2b285cd + 295c70e commit 649251f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/librustdoc/doctest/runner.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ impl DocTestRunner {
4747
self.crate_attrs.insert(line.to_string());
4848
}
4949
}
50-
if !self.ids.is_empty() {
51-
self.ids.push(',');
52-
}
5350
self.ids.push_str(&format!(
54-
"{}::TEST",
51+
"tests.push({}::TEST);\n",
5552
generate_mergeable_doctest(
5653
doctest,
5754
scraped_test,
@@ -142,19 +139,23 @@ mod __doctest_mod {{
142139
143140
#[rustc_main]
144141
fn main() -> std::process::ExitCode {{
145-
const TESTS: [test::TestDescAndFn; {nb_tests}] = [{ids}];
142+
let tests = {{
143+
let mut tests = Vec::with_capacity({nb_tests});
144+
{ids}
145+
tests
146+
}};
146147
let test_marker = std::ffi::OsStr::new(__doctest_mod::RUN_OPTION);
147148
let test_args = &[{test_args}];
148149
const ENV_BIN: &'static str = \"RUSTDOC_DOCTEST_BIN_PATH\";
149150
150151
if let Ok(binary) = std::env::var(ENV_BIN) {{
151152
let _ = crate::__doctest_mod::BINARY_PATH.set(binary.into());
152153
unsafe {{ std::env::remove_var(ENV_BIN); }}
153-
return std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), None));
154+
return std::process::Termination::report(test::test_main(test_args, tests, None));
154155
}} else if let Ok(nb_test) = std::env::var(__doctest_mod::RUN_OPTION) {{
155156
if let Ok(nb_test) = nb_test.parse::<usize>() {{
156-
if let Some(test) = TESTS.get(nb_test) {{
157-
if let test::StaticTestFn(f) = test.testfn {{
157+
if let Some(test) = tests.get(nb_test) {{
158+
if let test::StaticTestFn(f) = &test.testfn {{
158159
return std::process::Termination::report(f());
159160
}}
160161
}}
@@ -164,7 +165,7 @@ if let Ok(binary) = std::env::var(ENV_BIN) {{
164165
165166
eprintln!(\"WARNING: No rustdoc doctest environment variable provided so doctests will be run in \
166167
the same process\");
167-
std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), None))
168+
std::process::Termination::report(test::test_main(test_args, tests, None))
168169
}}",
169170
nb_tests = self.nb_tests,
170171
output = self.output_merged_tests,

0 commit comments

Comments
 (0)