Skip to content

Commit b42e9a3

Browse files
Add fallback in case the "all in one" doctests failed to compile
1 parent 3a02b71 commit b42e9a3

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/librustdoc/doctest.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub(crate) fn run(
225225
})
226226
})?;
227227

228-
tests.run_tests(test_args, nocapture, opts);
228+
tests.run_tests(test_args, nocapture, opts, &unused_extern_reports);
229229

230230
// Collect and warn about unused externs, but only if we've gotten
231231
// reports for each doctest
@@ -1256,7 +1256,7 @@ impl DocTestKinds {
12561256
opts: &GlobalTestOptions,
12571257
edition: Edition,
12581258
path: PathBuf,
1259-
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
1259+
unused_externs: &Arc<Mutex<Vec<UnusedExterns>>>,
12601260
) {
12611261
if doctest.failed_ast
12621262
|| doctest.lang_string.compile_fail
@@ -1268,7 +1268,7 @@ impl DocTestKinds {
12681268
opts,
12691269
edition,
12701270
path,
1271-
unused_externs,
1271+
Arc::clone(unused_externs),
12721272
));
12731273
} else {
12741274
self.others.entry(edition).or_default().push(doctest);
@@ -1280,6 +1280,7 @@ impl DocTestKinds {
12801280
mut test_args: Vec<String>,
12811281
nocapture: bool,
12821282
opts: GlobalTestOptions,
1283+
unused_externs: &Arc<Mutex<Vec<UnusedExterns>>>,
12831284
) {
12841285
test_args.insert(0, "rustdoctest".to_string());
12851286
if nocapture {
@@ -1305,7 +1306,7 @@ impl DocTestKinds {
13051306
let outdir = Arc::clone(&doctests[0].outdir);
13061307

13071308
let mut supports_color = true;
1308-
for (pos, doctest) in doctests.into_iter().enumerate() {
1309+
for (pos, doctest) in doctests.iter().enumerate() {
13091310
if !ids.is_empty() {
13101311
ids.push(',');
13111312
}
@@ -1336,7 +1337,17 @@ fn main() {{
13361337
PathBuf::from(format!("doctest_edition_{edition}.rs")),
13371338
|_: UnusedExterns| {},
13381339
) {
1339-
// FIXME: run all tests one by one.
1340+
// We failed to compile all compatible tests as one so we push them into the
1341+
// "standalone" doctests.
1342+
debug!("Failed to compile compatible doctests for edition {edition} all at once");
1343+
for (pos, doctest) in doctests.into_iter().enumerate() {
1344+
standalone.push(doctest.generate_test_desc_and_fn(
1345+
&opts,
1346+
edition,
1347+
format!("doctest_{edition}_{pos}").into(),
1348+
Arc::clone(unused_externs),
1349+
));
1350+
}
13401351
}
13411352
}
13421353

@@ -1500,13 +1511,7 @@ impl Tester for Collector {
15001511
test_id,
15011512
&target_str,
15021513
);
1503-
self.tests.add_doctest(
1504-
doctest,
1505-
&opts,
1506-
edition,
1507-
path,
1508-
Arc::clone(&self.unused_extern_reports),
1509-
);
1514+
self.tests.add_doctest(doctest, &opts, edition, path, &self.unused_extern_reports);
15101515
}
15111516

15121517
fn get_line(&self) -> usize {

src/librustdoc/markdown.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fmt::Write as _;
22
use std::fs::{create_dir_all, read_to_string, File};
33
use std::io::prelude::*;
44
use std::path::Path;
5+
use std::sync::{Arc, Mutex};
56

67
use tempfile::tempdir;
78

@@ -177,6 +178,7 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
177178
false,
178179
);
179180

180-
collector.tests.run_tests(options.test_args, options.nocapture, opts);
181+
let unused_externs = Arc::new(Mutex::new(Vec::new()));
182+
collector.tests.run_tests(options.test_args, options.nocapture, opts, &unused_externs);
181183
Ok(())
182184
}

0 commit comments

Comments
 (0)