Skip to content

Commit 0da332c

Browse files
committed
fix(docscrape): must fail with bad build script
When running `cargo doc -Zrustdoc-scrape-example`, it performs additional type checks that a plain old `cargo doc` doesn't. That leads to some extra failure when adopting scrape-example for docs.rs. In de34d60 we introduced `unit_can_fail_for_docscraping` in order to make `-Zrustdoc-scrape-example` not fail whenever `cargo doc` builds. Build script executions were accidentally included in the list of fallible units. A plain `cargo doc` does fail when a build script fails. `-Zrustdoc-scrape-example` should follow that.
1 parent a481387 commit 0da332c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/cargo/core/compiler/rustdoc.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,24 @@ impl RustdocScrapeExamples {
211211
}
212212

213213
impl BuildContext<'_, '_> {
214-
/// Returns the set of Docscrape units that have a direct dependency on `unit`
214+
/// Returns the set of [`Docscrape`] units that have a direct dependency on `unit`.
215+
///
216+
/// [`RunCustomBuild`] units are excluded because we allow failures
217+
/// from type checks but not build script executions.
218+
/// A plain old `cargo doc` would just die if a build script execution fails,
219+
/// there is no reason for `-Zrustdoc-scrape-examples` to keep going.
220+
///
221+
/// [`Docscrape`]: crate::core::compiler::CompileMode::Docscrape
222+
/// [`RunCustomBuild`]: crate::core::compiler::CompileMode::Docscrape
215223
pub fn scrape_units_have_dep_on<'a>(&'a self, unit: &'a Unit) -> Vec<&'a Unit> {
216224
self.scrape_units
217225
.iter()
218226
.filter(|scrape_unit| {
219227
self.unit_graph[scrape_unit]
220228
.iter()
221-
.any(|dep| &dep.unit == unit)
229+
.any(|dep| &dep.unit == unit && !dep.unit.mode.is_run_custom_build())
222230
})
223-
.collect::<Vec<_>>()
231+
.collect()
224232
}
225233

226234
/// Returns true if this unit is needed for doing doc-scraping and is also

tests/testsuite/docscrape.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,11 @@ fn fail_bad_build_script() {
389389
.with_stderr_contains("[..]You shall not pass[..]")
390390
.run();
391391

392-
// FIXME: scrape examples should fail whenever `cargo doc` fails.
392+
// scrape examples should fail whenever `cargo doc` fails.
393393
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
394394
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
395-
.with_stderr(
396-
"\
397-
[COMPILING] foo v0.0.1 ([CWD])
398-
[SCRAPING] foo v0.0.1 ([CWD])
399-
[DOCUMENTING] foo v0.0.1 ([CWD])
400-
[FINISHED] dev [..]
401-
",
402-
)
395+
.with_status(101)
396+
.with_stderr_contains("[..]You shall not pass[..]")
403397
.run();
404398
}
405399

0 commit comments

Comments
 (0)