You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #11450 - willcrichton:example-analyzer, r=weihanglo
Allow Check targets needed for optional doc-scraping to fail without killing the build
### What does this PR try to resolve?
In doing a Crater run of -Zrustdoc-scrape-examples, I found that the only remaining regressions are cases where:
* A library does not type-check
* The library has examples
* Cargo tries to scrape the examples, which requires checking the library
* The Check unit for the library fails, crashing the build
The core issue is that the Check unit should be able to fail without killing the build. This PR fixes this issue by checking for this condition, and then allowing the unit to fail.
Specifically, I added a new method `BuildContext::unit_can_fail_for_docscraping` that determines the conditions for whether a unit is allowed to fail. This method is used both in `JobQueue` to interpret process failure, and in the `rustc`/`rustdoc` functions to emit a warning upon failure. I modified `rustc` to handle the case of failure similar to `rustdoc`, but with a slightly different diagnostic.
### How should we test and review this PR?
The unit test `no_fail_bad_lib` has been extended with example files to test this case.
r? `@weihanglo`
let failed_scrape_diagnostic = hide_diagnostics_for_scrape_unit.then(|| {
293
+
// If this unit is needed for doc-scraping, then we generate a diagnostic that
294
+
// describes the set of reverse-dependencies that cause the unit to be needed.
295
+
let target_desc = unit.target.description_named();
296
+
letmut for_scrape_units = cx
297
+
.bcx
298
+
.scrape_units_have_dep_on(unit)
299
+
.into_iter()
300
+
.map(|unit| unit.target.description_named())
301
+
.collect::<Vec<_>>();
302
+
for_scrape_units.sort();
303
+
let for_scrape_units = for_scrape_units.join(", ");
304
+
make_failed_scrape_diagnostic(cx, unit,format_args!("failed to check {target_desc} in package `{name}` as a prerequisite for scraping examples from: {for_scrape_units}"))
305
+
});
306
+
if hide_diagnostics_for_scrape_unit {
307
+
output_options.show_diagnostics = false;
308
+
}
309
+
268
310
returnOk(Work::new(move |state| {
269
311
// Artifacts are in a different location than typical units,
270
312
// hence we must assure the crate- and target-dependent
warning: failed to scan lib in package `foo` for example code usage
343
346
Try running with `--verbose` to see the error message.
344
-
If this example should not be scanned, consider adding `doc-scrape-examples = false` to the `[[example]]` definition in Cargo.toml
347
+
If an example or library should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` or `[lib]` definition in Cargo.toml
345
348
warning: `foo` (lib) generated 1 warning
349
+
warning: failed to check lib in package `foo` as a prerequisite for scraping examples from: example \"ex\", example \"ex2\"
350
+
Try running with `--verbose` to see the error message.
351
+
If an example or library should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` or `[lib]` definition in Cargo.toml
352
+
warning: `foo` (lib) generated 1 warning
353
+
warning: failed to scan example \"ex\" in package `foo` for example code usage
354
+
Try running with `--verbose` to see the error message.
355
+
If an example or library should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` or `[lib]` definition in Cargo.toml
warning: failed to scan example \"ex2\" in package `foo` for example code usage
358
+
Try running with `--verbose` to see the error message.
359
+
If an example or library should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` or `[lib]` definition in Cargo.toml
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
348
363
)
@@ -374,7 +389,7 @@ fn no_fail_bad_example() {
374
389
[SCRAPING] foo v0.0.1 ([CWD])
375
390
warning: failed to scan example \"ex1\" in package `foo` for example code usage
376
391
Try running with `--verbose` to see the error message.
377
-
If this example should not be scanned, consider adding `doc-scrape-examples = false` to the `[[example]]` definition in Cargo.toml
392
+
If an example or library should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` or `[lib]` definition in Cargo.toml
0 commit comments