Skip to content

Commit 295c70e

Browse files
committed
Fix O(tests) stack usage in edition 2024 mergeable doctests
1 parent 385970f commit 295c70e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Diff for: src/librustdoc/doctest/runner.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ impl DocTestRunner {
4545
self.crate_attrs.insert(line.to_string());
4646
}
4747
}
48-
if !self.ids.is_empty() {
49-
self.ids.push(',');
50-
}
5148
self.ids.push_str(&format!(
52-
"{}::TEST",
49+
"tests.push({}::TEST);\n",
5350
generate_mergeable_doctest(
5451
doctest,
5552
scraped_test,
@@ -136,19 +133,23 @@ mod __doctest_mod {{
136133
137134
#[rustc_main]
138135
fn main() -> std::process::ExitCode {{
139-
const TESTS: [test::TestDescAndFn; {nb_tests}] = [{ids}];
136+
let tests = {{
137+
let mut tests = Vec::with_capacity({nb_tests});
138+
{ids}
139+
tests
140+
}};
140141
let test_marker = std::ffi::OsStr::new(__doctest_mod::RUN_OPTION);
141142
let test_args = &[{test_args}];
142143
const ENV_BIN: &'static str = \"RUSTDOC_DOCTEST_BIN_PATH\";
143144
144145
if let Ok(binary) = std::env::var(ENV_BIN) {{
145146
let _ = crate::__doctest_mod::BINARY_PATH.set(binary.into());
146147
unsafe {{ std::env::remove_var(ENV_BIN); }}
147-
return std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), None));
148+
return std::process::Termination::report(test::test_main(test_args, tests, None));
148149
}} else if let Ok(nb_test) = std::env::var(__doctest_mod::RUN_OPTION) {{
149150
if let Ok(nb_test) = nb_test.parse::<usize>() {{
150-
if let Some(test) = TESTS.get(nb_test) {{
151-
if let test::StaticTestFn(f) = test.testfn {{
151+
if let Some(test) = tests.get(nb_test) {{
152+
if let test::StaticTestFn(f) = &test.testfn {{
152153
return std::process::Termination::report(f());
153154
}}
154155
}}
@@ -158,7 +159,7 @@ if let Ok(binary) = std::env::var(ENV_BIN) {{
158159
159160
eprintln!(\"WARNING: No rustdoc doctest environment variable provided so doctests will be run in \
160161
the same process\");
161-
std::process::Termination::report(test::test_main(test_args, Vec::from(TESTS), None))
162+
std::process::Termination::report(test::test_main(test_args, tests, None))
162163
}}",
163164
nb_tests = self.nb_tests,
164165
output = self.output,

0 commit comments

Comments
 (0)